1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Http\Livewire\Admin\Download; |
4
|
|
|
|
5
|
|
|
use Adminetic\Website\Models\Admin\Download; |
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 DownloadTable extends DataTableComponent |
12
|
|
|
{ |
13
|
|
|
public function builder(): Builder |
14
|
|
|
{ |
15
|
|
|
return Download::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
|
|
|
Download::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 download 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
|
|
|
Download::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
|
|
|
->format( |
55
|
|
|
fn ($value, $row, Column $column) => '<a href="'.$row->getFirstMediaUrl('file').'" download>'.$row->name.'</a>' |
|
|
|
|
56
|
|
|
) |
57
|
|
|
->html() |
58
|
|
|
->sortable() |
59
|
|
|
->searchable(), |
60
|
|
|
Column::make('Action') |
61
|
|
|
->label( |
62
|
|
|
fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="download" :show="0" />', ['model' => $row]) |
|
|
|
|
63
|
|
|
) |
64
|
|
|
->html() |
65
|
|
|
->collapseOnTablet(), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|