46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
/**
|
||
|
* @var \Illuminate\Database\Eloquent\Collection $menu
|
||
|
*/
|
||
|
|
||
|
use app\models\User;
|
||
|
use Itguild\EloquentTable\ViewEloquentTable;
|
||
|
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||
|
use kernel\IGTabel\btn\DangerBtn;
|
||
|
use kernel\IGTabel\btn\PrimaryBtn;
|
||
|
use kernel\IGTabel\btn\SuccessBtn;
|
||
|
use kernel\models\Menu;
|
||
|
|
||
|
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($menu, [
|
||
|
'params' => ["class" => "table table-bordered", "border" => "2"],
|
||
|
'baseUrl' => "/admin/menu",
|
||
|
]));
|
||
|
$table->beforePrint(function () use ($menu) {
|
||
|
$btn = PrimaryBtn::create("Список", "/admin/menu")->fetch();
|
||
|
$btn .= SuccessBtn::create("Редактировать", "/admin/menu/update/" . $menu->id)->fetch();
|
||
|
$btn .= DangerBtn::create("Удалить", "/admin/menu/delete/" . $menu->id)->fetch();
|
||
|
return $btn;
|
||
|
});
|
||
|
$table->rows([
|
||
|
'parent_id' => (function ($data) {
|
||
|
if ($data == 0) return null;
|
||
|
return Menu::find($data)->label;
|
||
|
}),
|
||
|
'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");
|
||
|
}
|
||
|
]);
|
||
|
$table->create();
|
||
|
$table->render();
|