65 lines
2.0 KiB
PHP
65 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Datatable\Studio\Loyalty;
|
|
|
|
use App\Models\Customer;
|
|
use App\Traits\Datatable\WithAppendColumn;
|
|
use App\Traits\Datatable\WithConfiguration;
|
|
use App\Traits\Datatable\WithPrependColumn;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
|
use Rappasoft\LaravelLivewireTables\Views\Column;
|
|
|
|
class CustomersTable extends DataTableComponent
|
|
{
|
|
use WithAppendColumn, WithConfiguration, WithPrependColumn;
|
|
|
|
protected $model = Customer::class;
|
|
|
|
public function columns(): array
|
|
{
|
|
return [
|
|
Column::make('Nama', 'name')->searchable(),
|
|
|
|
Column::make('Nomor Telepon', 'phone_number')->searchable(),
|
|
|
|
Column::make('Jenis Kelamin', 'gender')
|
|
->format(fn ($value) => Blade::render(
|
|
'<flux:badge color="'.$value->color().'">'
|
|
.$value->label()
|
|
.'</flux:badge>'
|
|
))
|
|
->html(),
|
|
|
|
Column::make('Aksi')
|
|
->label(function ($row) {
|
|
$actions = '';
|
|
|
|
if (auth()->user()->can('update customer')) {
|
|
$actions .= view('components.datatables.edit-modal', [
|
|
'id' => $row->id,
|
|
'method' => 'update',
|
|
'modalTitle' => 'Ubah Customer',
|
|
])->render();
|
|
}
|
|
|
|
if (auth()->user()->can('delete customer')) {
|
|
$actions .= view('components.datatables.delete', [
|
|
'id' => $row->id,
|
|
'deleteRoute' => route('studio.loyalty.customer.delete', $row->id),
|
|
])->render();
|
|
}
|
|
|
|
return $actions;
|
|
})
|
|
->html(),
|
|
];
|
|
}
|
|
|
|
public function builder(): Builder
|
|
{
|
|
return Customer::select('id', 'name', 'phone_number', 'gender');
|
|
}
|
|
}
|