romalytvynenko/eloquent-table
Composer 安装命令:
composer require romalytvynenko/eloquent-table
包简介
README 文档
README
Add folowing line to your composer.json:
"romalytvynenko/eloquent-table": "dev-master"
Add following lines to config/app.php (providers)
'Romalytvynenko\EloquentTable\EloquentTableServiceProvider'
And this part to aliases section
'EloquentTable' => 'Romalytvynenko\EloquentTable\Engine\EloquentTable'
Usage
First of all, cerate EloquentTable object.
$exampleTable = new EloquentTable('Example', $tableSettings);
Where first parameter is model name, and $tableSettings is special table settings used for current table. You could also provide some specific params, such as 'searchable' and 'preGet'. Where 'searchable' is array of columns which will be searchable (what a twist!), and 'preGet' is closure that will applied to query before all other filters (search, sort, etc.)
$tableSettings = [ 'columns' => [ 'id' => '#', 'title' => 'Title', 'message' => 'Message', 'sent_at' => 'Sent', ], 'sortable' => [ 'id', 'sent_at' ], 'searchable' => [ 'title' ], 'preGet' => function($query) { /** * @var $query \Illuminate\Database\Query\Builder */ return $query->where('type', 'group'); }, ];
And now you could render table using show method:
$exampleTable->show();
Changing column output
For changing columns output you can use closures for hooking output:
$table->columnOutput('id', function($item){ /** * @var $item \Eloquent */ return 'Item - ' . $item->id; });
Where id is example of column name, and anonymous function - is the example of a function wich result will be used instead of original column value.
Your own table layout
You can easyli create your own table layout. For those purpose look at views/table.php sources, and feel free to create iyour own. You can use it passing to the show function your view name:
$exampleTable->show('admin.table');
统计信息
- 总下载量: 843
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-03-03