setTitle("Список карт"); $view->setMeta([ 'description' => 'Список карт системы' ]); $get = (new \kernel\Request())->get(); //Для использования таблицы с моделью, необходимо создать таблицу в базе данных $table = new ListEloquentTable(new EloquentDataProvider(Card::query()->orderBy("id", "DESC"), [ 'currentPage' => $page_number, 'perPage' => 8, 'params' => ["class" => "table table-bordered", "border" => "2"], 'baseUrl' => "/admin/card", 'searchPrefix' => "", 'searchParams' => $get, 'fillable' => [ 'user_id', 'balance', 'username', 'card_template_id', 'card_file_id', 'status', ], ])); $table->columns([ 'user_id' => [ 'value' => function ($data) { return User::find($data)->username ?? ''; } ], 'card_template_id' => [ 'value' => function ($data) { return \kernel\app_modules\card\models\CardTemplate::find($data)->title; } ], "username" => [ "filter" => [ "class" => \Itguild\Tables\Filter\InputTextFilter::class, 'value' => $get['username'] ?? '' ] ], 'card_file_id' => [ 'value' => function ($data) { $file = \kernel\app_modules\card\models\CardFile::find($data)->file; return $file ? \kernel\helpers\Html::img($file) : ""; } ], 'status' => [ 'value' => function ($data) { return Card::getStatus()[$data]; }, 'filter' => [ 'class' => \kernel\filters\BootstrapSelectFilter::class, 'params' => [ 'options' => Card::getStatus(), 'prompt' => 'Не выбрано' ], 'value' => $get['status'] ?? '', ], ] ]); $table->beforePrint(function () use ($table) { $count = Card::all()->count(); $html = IconBtnCreateWidget::create(['url' => '/admin/card/create'])->run(); $html .= "
Всего записей: $count
"; return $html; }); $table->addAction(function($row) { return IconBtnViewWidget::create(['url' => '/admin/card/' . $row['id']])->run(); }); $table->addAction(function($row) { return IconBtnEditWidget::create(['url' => '/admin/card/update/' . $row['id']])->run(); }); $table->addAction(function($row) { return IconBtnDeleteWidget::create(['url' => '/admin/card/delete/' . $row['id']])->run(); }); $table->create(); $table->render();