2024-07-25 16:15:18 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2024-07-26 11:57:05 +03:00
|
|
|
* @var \Illuminate\Database\Eloquent\Collection $content
|
2024-07-25 16:15:18 +03:00
|
|
|
*/
|
2024-08-07 15:30:45 +03:00
|
|
|
|
2024-09-06 16:53:20 +03:00
|
|
|
use kernel\modules\user\models\User;
|
2024-08-07 15:30:45 +03:00
|
|
|
use Itguild\EloquentTable\ViewEloquentTable;
|
|
|
|
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
2024-07-25 16:15:18 +03:00
|
|
|
use kernel\IGTabel\btn\DangerBtn;
|
|
|
|
use kernel\IGTabel\btn\PrimaryBtn;
|
|
|
|
use kernel\IGTabel\btn\SuccessBtn;
|
|
|
|
|
2024-08-07 15:30:45 +03:00
|
|
|
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [
|
2024-07-25 16:15:18 +03:00
|
|
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
2024-08-07 15:30:45 +03:00
|
|
|
'baseUrl' => "/admin/post",
|
|
|
|
]));
|
|
|
|
$table->beforePrint(function () use ($content) {
|
2024-07-25 16:15:18 +03:00
|
|
|
$btn = PrimaryBtn::create("Список", "/admin/post")->fetch();
|
2024-07-26 11:57:05 +03:00
|
|
|
$btn .= SuccessBtn::create("Редактировать", "/admin/post/update/" . $content->id)->fetch();
|
|
|
|
$btn .= DangerBtn::create("Удалить", "/admin/post/delete/" . $content->id)->fetch();
|
2024-07-25 16:15:18 +03:00
|
|
|
return $btn;
|
|
|
|
});
|
2024-08-07 15:30:45 +03:00
|
|
|
$table->rows([
|
|
|
|
'created_at' => function ($data) {
|
|
|
|
if (!$data){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
})
|
|
|
|
]);
|
2024-07-25 16:15:18 +03:00
|
|
|
$table->create();
|
|
|
|
$table->render();
|