diff options
author | Sam Light <samlight1994@gmail.com> | 2023-11-05 19:38:00 +0000 |
---|---|---|
committer | Sam Light <samlight1994@gmail.com> | 2023-11-05 19:38:00 +0000 |
commit | 5c24746657ac23c7a65c4e4efc89cf6bfcb5a52c (patch) | |
tree | 3de215fe85096429e615127172a2cee0b56661b0 /src/TableComponent.php | |
parent | bb6795b604e5686ee069c48dd7f7ce8cc3bf73c3 (diff) |
Built basic table
Diffstat (limited to 'src/TableComponent.php')
-rw-r--r-- | src/TableComponent.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/TableComponent.php b/src/TableComponent.php new file mode 100644 index 0000000..e530415 --- /dev/null +++ b/src/TableComponent.php @@ -0,0 +1,55 @@ +<?php + +namespace Lightscale\LaralightTables; + +use Livewire\Component; +use Livewire\WithPagination; + +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Model; + +use Exception; + +abstract class TableComponent extends Component +{ + use WithPagination; + + protected $paginationTheme = 'bootstrap'; + protected bool $searchable = true; + + protected Model $model = null; + + 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 buildQuery() : Builder + { + $query = $this->query(); + } + + public function render() + { + $this->buildQuery()->paginate(); + $data = $query->paginate($this->pageSize); + $columns = $this->columns(); + + return view('laralight-tables::table', compact( + 'data', 'columns' + )); + } +} |