- memperbaiki pemanggilan component karena sebelumnya dirubah path nya - kasih return type - kasih HasFactory doi model
98 lines
3.9 KiB
PHP
98 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Datatable\Studio\Feature;
|
|
|
|
use App\Models\PerfumeFeature;
|
|
use App\Traits\Datatable\WithConfiguration;
|
|
use App\Traits\Datatable\WithPrependColumn;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
|
use Rappasoft\LaravelLivewireTables\Views\Column;
|
|
|
|
class PerfumeFeaturesTable extends DataTableComponent
|
|
{
|
|
use WithConfiguration, WithPrependColumn;
|
|
|
|
protected $model = PerfumeFeature::class;
|
|
|
|
public function columns(): array
|
|
{
|
|
return [
|
|
Column::make('Nama', 'name')->searchable()->sortable(),
|
|
|
|
Column::make('Keterangan', 'description')->searchable()->sortable(),
|
|
|
|
Column::make('Aksi')
|
|
->label(function ($row) {
|
|
$actions = '';
|
|
$maxSortOrder = PerfumeFeature::max('sort_order');
|
|
|
|
if (auth()->user()->can('update perfume feature')) {
|
|
if ($row->sort_order > 1) {
|
|
$actions .= view('components.actions.table.sort-button', [
|
|
'id' => $row->hash,
|
|
'module' => 'perfumeFeature',
|
|
'direction' => 'up',
|
|
'tooltip' => 'Naik',
|
|
'color' => 'cyan',
|
|
'icon' => 'arrow-up',
|
|
])->render();
|
|
|
|
$actions .= view('components.actions.table.sort-button', [
|
|
'id' => $row->hash,
|
|
'module' => 'perfumeFeature',
|
|
'direction' => 'first',
|
|
'tooltip' => 'Pertama',
|
|
'color' => 'emerald',
|
|
'icon' => 'bars-arrow-up',
|
|
])->render();
|
|
}
|
|
|
|
if ($row->sort_order < $maxSortOrder) {
|
|
$actions .= view('components.actions.table.sort-button', [
|
|
'id' => $row->hash,
|
|
'module' => 'perfumeFeature',
|
|
'direction' => 'down',
|
|
'tooltip' => 'Turun',
|
|
'color' => 'orange',
|
|
'icon' => 'arrow-down',
|
|
])->render();
|
|
|
|
$actions .= view('components.actions.table.sort-button', [
|
|
'id' => $row->hash,
|
|
'module' => 'perfumeFeature',
|
|
'direction' => 'last',
|
|
'tooltip' => 'Terakhir',
|
|
'color' => 'rose',
|
|
'icon' => 'bars-arrow-down',
|
|
])->render();
|
|
}
|
|
}
|
|
|
|
if (auth()->user()->can('update perfume feature')) {
|
|
$actions .= view('components.actions.table.edit-modal', [
|
|
'id' => $row->hash,
|
|
'method' => 'update',
|
|
'modalTitle' => 'Ubah Kategori',
|
|
])->render();
|
|
}
|
|
|
|
if (auth()->user()->can('delete perfume feature')) {
|
|
$actions .= view('components.actions.table.delete', [
|
|
'id' => $row->hash,
|
|
])->render();
|
|
}
|
|
|
|
return $actions;
|
|
})
|
|
->html()
|
|
->hideIf(auth()->user()->cannot('update perfume feature') && auth()->user()->cannot('delete perfume feature')),
|
|
];
|
|
}
|
|
|
|
public function builder(): Builder
|
|
{
|
|
return PerfumeFeature::select('id', 'name', 'description', 'sort_order')->orderBy('sort_order');
|
|
}
|
|
}
|