$query Results from query() method. */ public function dataTable(QueryBuilder $query): EloquentDataTable { return (new EloquentDataTable($query)) ->editColumn('auth_type', fn (Client $client) => $client->auth_type->label()) ->addColumn( 'action', fn (Client $client) => view('components.datatables.action-button', [ 'log' => true, 'edit' => [ 'modal' => 'client-form-modal', 'permission' => auth()->user()->can('update', $client), ], 'delete' => [ 'url' => null, 'title' => __('ui/button.delete'), 'message' => __('ui/confirmation.delete', ['resource' => __('resources.client')]), 'success_message' => __('ui/crud.success.deleted', ['resource' => __('resources.client')]), 'permission' => auth()->user()->can('delete', $client), ], 'table_name' => 'client-table', 'id' => $client->ulid, ]) ) ->rawColumns(['action']) ->addIndexColumn(); } /** * Get the query source of dataTable. * * @return QueryBuilder */ public function query(Client $model): QueryBuilder { return $model->newQuery(); } /** * Optional method if you want to use the html builder. */ public function html(): HtmlBuilder { return $this->builder() ->setTableId('client-table') ->columns($this->getColumns()) ->minifiedAjax() ->orderBy(-1) ->layout([ 'topStart' => [ 'rowClass' => 'row gap-1', 'className' => 'col-md-auto me-auto d-flex flex-sm-row flex-column justify-content-center justify-content-md-start align-items-center align-items-md-start gap-1', 'features' => ['buttons', 'pageLength'], ], 'topEnd' => [ 'className' => 'col-md-auto ms-auto d-flex flex-sm-row flex-column justify-content-center justify-content-md-end align-items-center align-items-md-start gap-1', 'features' => ['search'], ], 'bottomStart' => 'info', 'bottomEnd' => 'paging', ]) ->parameters([ 'language' => [ 'search' => '', 'searchPlaceholder' => __('ui/button.lookup'), ], 'fixedColumns' => [ 'start' => 2, ], 'scrollX' => true, 'scrollCollapse' => true, 'responsive' => true, ]) ->buttons([ Button::make('add') ->action('javascript:void(0)') ->attr(['data-coreui-toggle' => 'modal', 'data-coreui-target' => '#client-form-modal']) ->text(svg('tabler-plus', ['width' => 16, 'height' => 16])->toHtml()) ->addClass('btn-sm'), Button::make() ->text(svg('tabler-api', ['width' => 16, 'height' => 16])->toHtml()) ->action('javascript:void(0)') ->attr(['data-coreui-toggle' => 'modal', 'data-coreui-target' => '#api-form-modal']) ->addClass('btn-sm btn-info'), Button::make('reload') ->text(svg('tabler-reload', ['width' => 16, 'height' => 16])->toHtml()) ->addClass('btn-sm'), ]); } /** * Get the dataTable columns definition. */ public function getColumns(): array { return [ Column::computed('DT_RowIndex') ->width(10) ->title('#'), Column::make('name') ->title(__('domains/channel/field.client.name')), Column::make('domain') ->title(__('domains/channel/field.client.domain')), Column::make('webhook') ->title(__('domains/channel/field.client.webhook')), Column::make('auth_type') ->title(__('domains/channel/field.client.auth_type')), Column::computed('action') ->title(__('ui/label.actions')) ->exportable(false) ->printable(false) ->width(60) ->addClass('text-center'), ]; } /** * Get the filename for export. */ protected function filename(): string { return 'Client_'.date('YmdHis'); } }