|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Http\Livewire\Admin\Counter; |
|
4
|
|
|
|
|
5
|
|
|
use Adminetic\Website\Models\Admin\Counter; |
|
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 CounterTable extends DataTableComponent |
|
12
|
|
|
{ |
|
13
|
|
|
public function builder(): Builder |
|
14
|
|
|
{ |
|
15
|
|
|
return Counter::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
|
|
|
Counter::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 counter 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
|
|
|
Counter::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('Count', 'count') |
|
57
|
|
|
->sortable() |
|
58
|
|
|
->searchable(), |
|
59
|
|
|
Column::make('Type', 'type') |
|
60
|
|
|
->format( |
|
61
|
|
|
fn ($value, $row, Column $column) => $row->type |
|
|
|
|
|
|
62
|
|
|
) |
|
63
|
|
|
->collapseOnTablet(), |
|
64
|
|
|
Column::make('Icon', 'icon') |
|
65
|
|
|
->format( |
|
66
|
|
|
fn ($value, $row, Column $column) => '<span class="'.$row->icon.' "></span>' |
|
|
|
|
|
|
67
|
|
|
) |
|
68
|
|
|
->html() |
|
69
|
|
|
->collapseOnTablet(), |
|
70
|
|
|
Column::make('Action') |
|
71
|
|
|
->label( |
|
72
|
|
|
fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="counter" :show="0" />', ['model' => $row]) |
|
|
|
|
|
|
73
|
|
|
) |
|
74
|
|
|
->html() |
|
75
|
|
|
->collapseOnTablet(), |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|