blob: e530415b2c33654350956ffd2f1ef722becde29e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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'
));
}
}
|