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('Kategori', 'category') ->label(fn ($row, $column) => Blade::render(''.$row->category->label().'')) ->html(), Column::make('Visibilitas', 'is_show') ->label(fn ($row, $column) => Blade::render(''.$row->is_show->label().'')) ->html(), Column::make('Tanggal') ->label(function ($row) { $startDate = formatDateLocalized($row->start_date); $startAgo = formatRelativeTime($row->start_date); $endDate = formatDateLocalized($row->end_date); $endAgo = formatRelativeTime($row->end_date); return <<
Tgl Dimulai: {$startDate} ({$startAgo})
Tgl Berakhir: {$endDate} ({$endAgo})
HTML; }) ->html(), Column::make('Aksi') ->label(function ($row) { $actions = ''; if (auth()->user()->can('update reward') && $row->redemptions_count === 0) { $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', 'category', 'is_show', 'start_date', 'end_date')->withCount('redemptions'); } }