MicroFrameWork/kernel/modules/post/views/view.php
2024-11-27 17:11:06 +03:00

49 lines
1.5 KiB
PHP

<?php
/**
* @var \Illuminate\Database\Eloquent\Collection $content
*/
use kernel\modules\user\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\widgets\IconBtn\IconBtnDeleteWidget;
use kernel\widgets\IconBtn\IconBtnEditWidget;
use kernel\widgets\IconBtn\IconBtnListWidget;
$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($content, [
'params' => ["class" => "table table-bordered", "border" => "2"],
'baseUrl' => "/admin/post",
]));
$table->beforePrint(function () use ($content) {
$btn = IconBtnListWidget::create(['url' => '/admin/post'])->run();
$btn .= IconBtnEditWidget::create(['url' => '/admin/post/update/' . $content->id])->run();
$btn .= IconBtnDeleteWidget::create(['url' => '/admin/post/delete/' . $content->id])->run();
return $btn;
});
$entityRelation = new \kernel\EntityRelation();
$additional = $entityRelation->getEntityAdditionalProperty("post", $content);
$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;
})
]);
$table->create();
$table->render();