summaryrefslogtreecommitdiff
path: root/src/TableComponent.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/TableComponent.php')
-rw-r--r--src/TableComponent.php55
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'
+ ));
+ }
+}