label(function ($row) { return <<
{$row->name}
{$row->code} HTML; }) ->searchable(function ($query, $searchTerm) { $query->where('name', 'like', "%{$searchTerm}%") ->orWhere('code', 'like', "%{$searchTerm}%"); }) ->html(), Column::make('Tags', 'tags') ->searchable() ->sortable(), Column::make('Min. Belanja', 'min_purchase') ->format(fn ($value) => currency($value, 'Rp')) ->searchable() ->sortable(), Column::make('Jumlah Diskon', 'discount_amount') ->label(fn ($row, $column) => formatDiscount($row->discount_amount, $row->type)) ->searchable() ->sortable(), Column::make('Maks. Diskon') ->label(fn ($row, $column) => currency($row->max_discount, 'Rp')) ->searchable() ->sortable(), Column::make('Kuota', 'quota') ->format(fn ($value) => $value ? currency($value) : 'Tidak Terbatas') ->searchable() ->sortable(), Column::make('Sisa Voucher', 'available_count') ->format(fn ($value) => $value ? currency($value) : 'Tidak Terbatas') ->searchable() ->sortable(), Column::make('Batas Per Pembali', 'limit_per_user') ->format(fn ($value) => $value ? $value : 'Tidak Terbatas') ->searchable() ->sortable(), ArrayColumn::make('Outlet') ->data( fn ($value, $row) => $row->outlets->map(fn ($outlet) => [ 'name' => $outlet->name, 'stock' => currency($outlet->pivot->stock, ''), ])->toArray() ) ->outputFormat(fn ($index, $value) => Blade::render('
{{ $value["name"] }}
', ['value' => $value])) ->flexRow(['class' => 'gap-2 flex-wrap']), Column::make('Tanggal') ->label(function ($row) { $startDate = formatDate($row->start_date); $startAgo = timeAgo($row->start_date); $endDate = formatDate($row->end_date); $endAgo = timeAgo($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 voucher')) { $actions .= view('components.datatables.edit', [ 'id' => $row->hash, 'editRoute' => route('studio.loyalty.voucher.edit', $row->hash), ])->render(); } if (auth()->user()->can('delete voucher')) { $actions .= view('components.datatables.delete', [ 'id' => $row->hash, 'deleteRoute' => route('studio.loyalty.voucher.delete', $row->hash), ])->render(); } return $actions; }) ->html() ->hideIf(auth()->user()->cannot('update voucher') && auth()->user()->cannot('delete voucher')), ]; } public function builder(): Builder { return Voucher::select('id', 'name', 'code', 'min_purchase', 'discount_amount', 'max_discount', 'quota', 'available_count', 'limit_per_user', 'start_date', 'end_date', 'type', 'created_at')->with('outlets'); } }