Each wiretable component is required to extend the columns() method, providing the array of Columns to render.
Most Column parameters are optional, and we can leverage PHP 8.0 named arguments to only specify what we need:
public function columns(): array
{
return [
Column::create(label: __('backend.created_at'), key: 'created_at', sort: true, dateFormat: 'd M y H:i' ),
Column::create(
label: __('backend.name'),
key: 'name',
map: fn ($user) => $user->first_name . ' ' . $user->last_name
),
Column::create(
label: '',
cellView: 'backend.users.actions',
thStyle: [ 'style' => 'width: 200px' ],
tdStyle: [ 'classList' => 'table-actions' ],
),
...
];
}label: Required. The header labelkey: Used as the model field for base rendering and sorting. It is not required if the column is not sortable and provides custom renderingsort: When true, the column will be sortable. False by defaultcellView: When provided, the blade view with that name will be rendered. Use$iteminside that blade view to refer to that row model (e.g.$item->idfor the user id).thStyle: Custom styling for the column th element. Expects aElementStyleobject or an array withstyleandclassListkeys.tdStyle: Same as thStyle, but applied to each td element of that column.dateFormat: Override thedate-formatoption in the config filemap: A closure, mapping the row model to a custom render string. Useful for simple transformations that does not require a custom viewisRaw: When true, the content will not be HTML-escaped. Not needed whencellViewis provided
If you implement custom row rendering, the parameters controlling how the cell is rendered will not be considered