cakmalik/livewire-generic-table
A flexible, Volt-friendly, and fully customizable table component for Laravel Livewire v3.
Designed for reusable admin tables with sorting, searching, actions, pagination, and custom column formatting.
Install via Composer:
composer require your-vendor/generic-table
If using Laravel < 10.21, publish views:
php artisan vendor:publish --tag=livewire-generic-table-views
<livewire:generic-table
:model="'App\\Models\\Post'"
:columns="$columns"
:queryParams="['keyword' => request('keyword')]"
defaultSortField="created_at"
defaultSortDirection="desc"
/>
Because Volt does not allow nested arrays inside state, you must use a computed property:
#[Computed]
public function columns(): array
{
return [
[
'label' => 'Title',
'field' => 'title',
'sortable' => true,
'searchable' => true,
],
[
'label' => 'Status',
'field' => 'status',
'format' => 'badge',
'badge' => [
'colors' => [
'draft' => 'bg-gray-100 text-gray-700',
'published' => 'bg-green-100 text-green-800',
],
'labels' => [
'draft' => 'Draft',
'published' => 'Published',
],
'default' => 'bg-gray-200 text-gray-900',
'default_label' => 'Unknown',
],
],
];
}
Then use it:
<livewire:generic-table
:model="$this->modelName"
:columns="$this->columns"
:queryParams="[
'keyword' => request('keyword')
]"
/>
Each column supports:
| Key | Description |
|---|---|
label |
Column header text |
field |
Column data field (supports nested relation.field) |
sortable |
Enable sorting |
searchable |
Enable keyword searching |
format |
text, image, badge, datetime, custom |
badge |
Configuration for badge colors & labels |
actions |
Row action buttons |
[
'label' => 'Actions',
'field' => 'actions',
'actions' => [
[
'event' => 'editAction',
'icon' => 'pencil',
'color' => 'indigo',
'variant' => 'primary',
],
[
'event' => 'deleteAction',
'icon' => 'trash',
'color' => 'red',
'variant' => 'danger',
],
],
],
Your component may listen to row action events:
#[On('editAction')]
public function edit($id)
{
// handle edit
}
You may override the view:
php artisan vendor:publish --tag=generic-table-views
Then edit:
resources/views/vendor/generic-table/generic-table.blade.php
Pull requests are welcome!
If you want to improve functionality, fix bugs, or extend features—feel free to contribute.
This package is open-sourced under the MIT License.
How can I help you explore Laravel packages today?