1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Http\Livewire\Admin\Gallery; |
4
|
|
|
|
5
|
|
|
use Adminetic\Website\Models\Admin\Gallery; |
6
|
|
|
use Illuminate\Database\Eloquent\Builder; |
7
|
|
|
use Illuminate\Support\Facades\Blade; |
8
|
|
|
use Rappasoft\LaravelLivewireTables\DataTableComponent; |
9
|
|
|
use Rappasoft\LaravelLivewireTables\Views\Column; |
10
|
|
|
|
11
|
|
|
class GalleryTable extends DataTableComponent |
12
|
|
|
{ |
13
|
|
|
public function builder(): Builder |
14
|
|
|
{ |
15
|
|
|
return Gallery::query()->orderBy('position'); // Eager load anything; // Select some things |
|
|
|
|
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public array $bulkActions = [ |
19
|
|
|
'bulkDelete' => 'Bulk Delete', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
public function bulkDelete() |
23
|
|
|
{ |
24
|
|
|
Gallery::whereIn('id', $this->getSelected())->delete(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function configure(): void |
28
|
|
|
{ |
29
|
|
|
$this->setPrimaryKey('id'); |
30
|
|
|
|
31
|
|
|
$this->setEagerLoadAllRelationsEnabled(); |
32
|
|
|
|
33
|
|
|
$this->setEmptyMessage('No gallery found'); |
34
|
|
|
|
35
|
|
|
$this->setReorderStatus(true); |
36
|
|
|
|
37
|
|
|
$this->setDefaultReorderSort('position', 'asc'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function reorder($items): void |
41
|
|
|
{ |
42
|
|
|
foreach ($items as $item) { |
43
|
|
|
Gallery::find((int) $item['value'])->update(['position' => (int) $item['order']]); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function columns(): array |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
Column::make('ID', 'id') |
51
|
|
|
->sortable() |
52
|
|
|
->searchable(), |
53
|
|
|
Column::make('Name', 'name') |
54
|
|
|
->sortable() |
55
|
|
|
->searchable(), |
56
|
|
|
Column::make('Action') |
57
|
|
|
->label( |
58
|
|
|
fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="gallery" :show="0" />', ['model' => $row]) |
|
|
|
|
59
|
|
|
) |
60
|
|
|
->html() |
61
|
|
|
->collapseOnTablet(), |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|