<?php

/**
 * @var \Illuminate\Database\Eloquent\Collection $tagEntity
 */

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;

$table = new ViewEloquentTable(new ViewJsonTableEloquentModel($tagEntity, [
    'params' => ["class" => "table table-bordered", "border" => "2"],
    'baseUrl' => "/admin/tag",
]));
$table->beforePrint(function () use ($tagEntity) {
    $btn = PrimaryBtn::create("Список", "/admin/tag_entity")->fetch();
    $btn .= SuccessBtn::create("Редактировать", "/admin/tag_entity/update/" . $tagEntity->id)->fetch();
    $btn .= DangerBtn::create("Удалить", "/admin/tag_entity/delete/" . $tagEntity->id)->fetch();
    return $btn;
});
$table->rows([
    'tag_id' => (function ($data) {
        return \kernel\app_modules\tag\models\Tag::find($data)->label;
    })
]);
$table->create();
$table->render();