add Eloquent Tables
This commit is contained in:
@ -2,25 +2,44 @@
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\Eloquent\Collection $contents
|
||||
* @var int $page_number
|
||||
*/
|
||||
|
||||
use app\models\Post;
|
||||
use app\models\User;
|
||||
use app\tables\columns\PostDeleteActionColumn;
|
||||
use app\tables\columns\PostEditActionColumn;
|
||||
use app\tables\columns\PostViewActionColumn;
|
||||
use Itguild\Tables\ListJsonTable;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
use kernel\IGTabel\ListJsonTableEloquentCollection;
|
||||
|
||||
$dataProvider = new ListJsonTableEloquentCollection($contents, [
|
||||
'model' => Post::class,
|
||||
'perPage' => 5,
|
||||
$table = new ListEloquentTable(new EloquentDataProvider(Post::class, [
|
||||
'currentPage' => $page_number,
|
||||
'perPage' => 3,
|
||||
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||||
'baseUrl' => "/admin/post",
|
||||
]);
|
||||
'baseUrl' => "/admin/post"
|
||||
]));
|
||||
$table->columns([
|
||||
'created_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = new ListJsonTable($dataProvider->getJson());
|
||||
$table->beforePrint(function (){
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'updated_at' => function ($data) {
|
||||
if (!$data){
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new DateTimeImmutable($data))->format("d-m-Y");
|
||||
},
|
||||
'user_id' => (function ($data) {
|
||||
return User::find($data)->username;
|
||||
})
|
||||
]);
|
||||
$table->beforePrint(function () {
|
||||
return PrimaryBtn::create("Создать", "/admin/post/create")->fetch();
|
||||
//return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
|
||||
});
|
||||
|
Reference in New Issue
Block a user