卡布奇诺 / laravel-table-view
Laravel 5 包,用于轻松显示 Eloquent 集合的表格视图。
v0.3.0
2020-03-04 07:45 UTC
Requires
- php: >=5.4
- illuminate/pagination: ~5|~6|~7
- illuminate/support: ~5|~6|~7
This package is auto-updated.
Last update: 2024-09-04 17:29:28 UTC
README
Laravel 5 包,用于轻松显示 Eloquent 集合的表格视图。
安装
composer require kabbouchi/laravel-table-view
接下来,您必须安装服务提供者
// config/app.php 'providers' => [ ... KABBOUCHI\TableView\TableViewServiceProvider::class, ];
您可以为表格视图发布和添加自定义样式
php artisan vendor:publish --provider="KABBOUCHI\TableView\TableViewServiceProvider" --tag="tableView"
用法
// Collection $users = User::all(); // or // Builder $users = User::query(); // User::where('active',true) ... tableView($users)->render();
$users = User::all(); tableView($users) ->column('ID', 'id') ->column('Active', 'active','boolean') ->column('Featured', 'active','boolean|No,Yes') ->column('Photo', 'photo','image') ->column('Avatar', 'avatar','image|200,200') ->column('full_name') // ->column('Full name','full_name') ->column('Created At', function ($model) { return $model->created_at->diffForHumans(); }) ->render();
// tableView with client side pagination (dataTable) // controller $users = collect([ (object) ["id" => 1, "user" => "User 1"], (object) ["id" => 2, "user" => "User 2"], (object) ["id" => 3, "user" => "User 3"], (object) ["id" => 4, "user" => "User 4"] ]); $table = tableView($users) ->setTableClass('table table-striped') ->useDataTable(); // You need to add @stack('scripts') and @stack('styles') in your main blade template // view $table->render();
// tableView with server side pagination // controller $users = User::all(); $table = tableView($users) ->column('ID', 'id') ->column('Active', 'active','boolean') ->column('Country', 'country.name') // $user->country->name ->column('Name', 'name:search') // enable search for names ->column('Created At', function ($model) { return $model->created_at->diffForHumans(); }) ->childDetails(function (User $user) { return view('partials.user-details',compact('user')); // return view or string }); ->appendsQueries(true) // or pass an Array for specific queries e.g: ['foo','bar'] ->paginate(); // default 15 // view $table->render();
为每个 tr
指定自定义属性
$table = tableView(User::all()) ->setTableRowAttributes([ 'class' => 'tr-class' ]);
使用闭包为每个 tr
指定自定义属性
$table = tableView(Category::all() ->setTableBodyClass('sortable') ->setTableRowAttributes(function (Category $categ) { return [ 'data-order-id' => $categ->order_index ]; });
许可证
MIT 许可证 (MIT)。请参阅许可证文件获取更多信息。