backend/views/admin/user/view.php

41 lines
1.2 KiB
PHP
Raw Normal View History

2024-07-25 11:55:31 +03:00
<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $user
*/
2024-08-07 15:30:45 +03:00
use app\models\User;
use Itguild\EloquentTable\ViewEloquentTable;
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
2024-07-25 13:23:50 +03:00
use kernel\IGTabel\btn\DangerBtn;
2024-07-25 11:55:31 +03:00
use kernel\IGTabel\btn\PrimaryBtn;
2024-07-25 13:23:50 +03:00
use kernel\IGTabel\btn\SuccessBtn;
2024-07-25 11:55:31 +03:00
2024-08-07 15:30:45 +03:00
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($user, [
2024-07-25 11:55:31 +03:00
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/user",
2024-08-07 15:30:45 +03:00
]));
$table->beforePrint(function () use ($user) {
2024-07-25 11:55:31 +03:00
$btn = PrimaryBtn::create("Список", "/admin/user")->fetch();
2024-07-25 13:23:50 +03:00
$btn .= SuccessBtn::create("Редактировать", "/admin/user/update/" . $user->id)->fetch();
$btn .= DangerBtn::create("Удалить", "/admin/user/delete/" . $user->id)->fetch();
2024-07-25 11:55:31 +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");
}
]);
2024-07-25 11:55:31 +03:00
$table->create();
$table->render();