<?php
namespace App\Livewire;
use App\Models\Employee;
use Arm092\LivewireDatatables\Column;
use Arm092\LivewireDatatables\Livewire\LivewireDatatable;
use Arm092\LivewireDatatables\NumberColumn;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class EmployeesTable extends LivewireDatatable
{
public string|null|Model $model = null;
public bool $exportable = true;
public function builder(): Builder
{
return Employee::query();
}
public function getColumns(): array|Model
{
return [
NumberColumn::name('id')
->label('ID'),
Column::name('first_name')
->defaultSort('asc')
->label('First Name')
->searchable(),
Column::name('middle_name')
->label('Middle Name')
->searchable(),
Column::name('last_name')
->label('Last Name')
->searchable(),
Column::name('birthday')
->label('Birthday'),
Column::name('address.line_address')
->label('Address')
->searchable(),
Column::name('address.city.name')
->label('City')
->searchable(),
Column::name('address.city.province.name')
->label('Province'),
Column::callback(['id'], function ($id) {
return view('employees.actions', ['id' => $id]);
})->excludeFromExport(),
];
}
}