<?php
/**
 * @var \Illuminate\Database\Eloquent\Collection $menuItem
 * @var int $page_number
 */

use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable;
use kernel\IGTabel\action_column\DeleteActionColumn;
use kernel\IGTabel\action_column\EditActionColumn;
use kernel\IGTabel\action_column\ViewActionColumn;
use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu;

$table = new ListEloquentTable(new EloquentDataProvider(Menu::class, [
    'currentPage' => $page_number,
    'perPage' => 8,
    'params' => ["class" => "table table-bordered", "border" => "2"],
    'baseUrl' => "/admin/settings/menu",
]));
$table->columns([
    'parent_id' => (function ($data) {
        if ($data == 0) return null;
        return Menu::find($data)->label;
    }),
]);
$table->beforePrint(function () {
    return PrimaryBtn::create("Создать", "/admin/settings/menu/create")->fetch();
    //return (new PrimaryBtn("Создать", "/admin/user/create"))->fetch();
});
$table->addAction(ViewActionColumn::class);
$table->addAction(EditActionColumn::class);
$table->addAction(DeleteActionColumn::class);
$table->create();
$table->render();