-
Notifications
You must be signed in to change notification settings - Fork 2
Defining a ListView instance
For simple ListViews where you need to define a few columns and nothing extra, it is easier to make an instance of Administr\ListView\ListView in your controller. But in other cases where you need to define a bit more columns with value formatters and many actions, it would be prettier to make a class that extends the package ListView and define your instance there.
In this case, the package provides a handy generator command:
php artisan administr:listview ExampleListView
This will generate an ExampleListView class in app/Http/ListViews/ExampleListView.php. You can define you columns in the columns() method and if you need filters in the filters() method. By default it will generate for you one column and create and edit actions. You can modify them as you wish.
<?php
namespace App\Http\ListViews;
use Administr\ListView\Columns\Action;
use Administr\ListView\Columns\Actions;
use Administr\ListView\Columns\Column;
use Administr\ListView\ListView;
use Administr\ListView\Filters\ListViewFilters;
class ExampleListView extends ListView
{
public function __construct($dataSource = null)
{
parent::__construct($dataSource);
$this->class = 'table table-bordered table-hover table-striped';
}
protected function columns()
{
$this
->text('id', '#')
->actions('', function(Actions $actions) {
$actions
->action('add', 'Добави')
->icon('fa fa-plus')
->url( route('app.examples.create') )
->setGlobal();
$actions
->action('edit', '')
->icon('fa fa-edit')
->define(function(Action $action, array $row){
$action->url( route('app.examples.edit', [$row['id']]) );
});
})
;
}
protected function filters(ListViewFilters $filter)
{
}
}