pageSize = $this->pageSizes[0] ?? 0; } public function mount() { foreach($this->getColumns() as $column) { $this->activeColumns[] = $column->name; } } protected function query() : Builder { if($this->model === null) { throw new Exception('Requires $model to be set or query() method to be overridden'); } return $this->model::query(); } abstract protected function columns() : array; protected function search(Builder $builder, string $search) : void {} protected function filters() : array { return []; } protected function buildQuery() : Builder { $query = $this->query(); if($this->searchable && (Str::length($this->search) >= $this->searchMinLength)) { $this->search($query, $this->search); } return $query; } protected function getColumns() { static $columns = null; if($columns === null) { $columns = collect($this->columns())->each( fn($c) => $c->setTable($this) ); } return $columns; } public function render() { $data = $this->buildQuery()->paginate($this->pageSize); $allColumns = $this->getColumns(); $columns = $allColumns->filter(fn($c) => in_array($c->name,$this->activeColumns)); return view('laralight-tables::table', [ 'searchable' => $this->searchable, 'searchDebounce' => $this->searchDebounce, 'showPageSizeSelect' => $this->showPageSizeSelect, 'showColumnSelect' => $this->showColumnSelect, 'pageSizes' => $this->pageSizes, ] + compact( 'data', 'allColumns', 'columns' )); } }