unlab/livewire-table-kit
Reusable Livewire table kit for Laravel with search, filters, sorting, pagination, row actions, bulk delete, and CSV/XLSX/PDF exports. Includes Tailwind-ready views, generators to scaffold tables from models, and optional MCP/AI skills.
## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require unlab/livewire-table-kit
Add Tailwind source path (v4):
@source "../../vendor/unlab/livewire-table-kit/resources/views/**/*.blade.php";
Run npm run build.
Generate a Table:
php artisan make:livewire-table App\Models\User UsersTable
This creates a scaffolded UsersTable component with:
First Use Case:
// app/Http/Livewire/UsersTable.php
public function columns(): array {
return [
Column::make('ID')->field('id')->sortable(),
Column::make('Name')->field('name')->searchable(),
];
}
<!-- resources/views/livewire/users-table.blade.php -->
<livewire:users-table />
columns() to match your model schema.Model-Driven Development:
make:livewire-table to auto-generate a table from an Eloquent model.Column Configuration:
// Dynamic value resolution
Column::make('Full Name')
->value(fn ($row) => "{$row->first_name} {$row->last_name}")
->searchableRaw('CONCAT(first_name, " ", last_name)');
// Custom Blade view for cells
Column::make('Status')
->field('status')
->view('custom.status-cell');
Filter Integration:
// Multi-select filter (checkbox)
Filter::checkbox('tags', 'Tags', [
'php' => 'PHP',
'laravel' => 'Laravel',
'livewire' => 'Livewire',
])->display('dropdown');
// Custom query logic
Filter::text('search_bio')
->query(fn ($query, $value) => $query->where('bio', 'like', "%{$value}%"));
Action Patterns:
// Row-level actions
ActionColumn::make()->actions([
TableAction::wire('Edit', fn ($row) => "edit({$row->id})"),
TableAction::link('View', fn ($row) => route('users.show', $row)),
]);
// Bulk actions
public function supportsBulkDelete(): bool => true;
public function actionBulkDelete(array $payload): void {
User::whereIn('id', $payload)->delete();
}
Export Workflow:
// Sync export (default)
public function supportsExport(): bool => true;
// Queued export (for large datasets)
protected function exportType(): string => 'queued';
protected function exportFilename(string $ext): string {
return "users_export_{$this->search}.{$ext}";
}
Column::make('Notes')->hiddenOn('sm');
refreshTable events to trigger data reloads:
$this->dispatch('refreshTable');
resources/views/vendor/livewire-table-kit/.Tailwind Configuration:
node_modules is rebuilt (npm run build).tailwind.config.js for v3:
content: [
'./vendor/unlab/livewire-table-kit/resources/views/**/*.blade.php',
'./resources/**/*.blade.php',
],
Filter Conflicts:
key values in Filter::*() methods.filters() array for duplicate keys.Export Failures:
protected function exportType(): string => 'queued';
livewire-table-kit.export.queued in config/livewire-table-kit.php:
'disk' => 'public',
'directory' => 'exports',
'queue' => 'default',
Sorting Quirks:
value() columns not sortable.Column::make('Full Name')
->value(fn ($row) => "{$row->first_name} {$row->last_name}")
->sortable('full_name'); // Custom sort field
Bulk Actions:
actionBulkDelete not triggering.supportsBulkDelete() returns true and the method is public.$payload contains expected IDs.$this->emit('alert', 'Debug message') in your table class.dd($this->filters);
query() to log the final query:
public function query(): Builder {
$query = User::query();
\Log::info('Table query:', ['query' => $query->toSql(), 'bindings' => $query->getBindings()]);
return $query;
}
Custom Columns:
Unlab\LivewireTableKit\Livewire\Components\Tables\Columns\Column for reusable column types (e.g., AvatarColumn).Filter Enhancements:
Filter::custom() to support non-standard inputs (e.g., date ranges):
Filter::custom('date_range', 'Date Range', function () {
return view('livewire-table-kit::filters.date-range');
})->query(function ($query, $value) {
return $query->whereBetween('created_at', $value);
});
Export Customization:
exportPdfTitle() or exportPdfMargins() for branded PDFs.ExportService to add custom export formats (e.g., JSON).AI Integration:
php artisan livewire-table-kit:install-mcp
Create a Livewire table for the Order model with columns for ID, customer name, total, and status. Include filters for status and date range, and add edit/view actions.
Queued Exports:
php artisan queue:work).PDF Chunking:
exportPdfChunkSize() and exportPdfChunkThreshold() for large datasets:
protected function exportPdfChunkSize(): int => 200;
protected function exportPdfChunkThreshold(): int => 1000;
Filter Toolbar:
protected function filterToolbarMode(): string => 'dropdown';
->lazy() on columns for large datasets:
Column::make('Description')->lazy()->field('description');
perPageOptions() for expected dataset sizes:
protected function perPageOptions(): array => [20, 50, 100];
protected function exportType(): string => 'queued';
protected function exportFilename(string $ext): string {
return "filtered_{$this->search}_{$ext}";
}
---
How can I help you explore Laravel packages today?