66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Datatable\Loyalty;
|
|
|
|
use App\Models\Reward;
|
|
use App\Traits\Datatable\WithAppendColumn;
|
|
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 RewardsTable extends DataTableComponent
|
|
{
|
|
use WithAppendColumn, WithConfiguration, WithPrependColumn;
|
|
|
|
protected $model = Reward::class;
|
|
|
|
public function columns(): array
|
|
{
|
|
return [
|
|
Column::make('Nama', 'name')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Column::make('Poin', 'points')
|
|
->format(fn ($value) => formatCurrencyNumber($value))
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Column::make('Stok', 'stock')
|
|
->format(fn ($value) => $value === null ? 'Tidak Terbatas' : formatCurrencyNumber($value))
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Column::make('Aksi')
|
|
->label(function ($row) {
|
|
$actions = '';
|
|
|
|
if (auth()->user()->can('update reward')) {
|
|
$actions .= view('components.actions.table.edit-modal', [
|
|
'id' => $row->hash,
|
|
'method' => 'update',
|
|
'modalTitle' => 'Ubah Hadiah',
|
|
])->render();
|
|
}
|
|
|
|
if (auth()->user()->can('delete reward')) {
|
|
$actions .= view('components.actions.table.delete', [
|
|
'id' => $row->hash,
|
|
])->render();
|
|
}
|
|
|
|
return $actions;
|
|
})
|
|
->html()
|
|
->hideIf(auth()->user()->cannot('update reward') && auth()->user()->cannot('delete reward')),
|
|
];
|
|
}
|
|
|
|
public function builder(): Builder
|
|
{
|
|
return Reward::select('id', 'name', 'points', 'stock');
|
|
}
|
|
}
|