## Getting Started
### Minimal Setup
1. **Install the package**:
```bash
composer require unlab/livewire-table-kit
Configure Tailwind (add to app.css or tailwind.config.js):
@source "../../vendor/unlab/livewire-table-kit/resources/views/**/*.blade.php";
Then run npm run build.
Generate a table component (replace User with your model):
php artisan make:livewire-table App\Models\User UsersTable
This auto-generates a UsersTable class with inferred columns (searchable/sortable fields, badges for booleans/statuses).
Use the table in a Blade view:
@livewire('users-table')
For a basic table with search, sorting, and pagination:
// app/Livewire/Tables/UsersTable.php
use Unlab\LivewireTableKit\Livewire\Components\Tables\BaseTable;
class UsersTable extends BaseTable {
public function query() { return User::query(); }
public function columns() { return [Column::make('Name')->field('name')->searchable()->sortable()]; }
}
This leverages the generator’s heuristics for minimal setup.
->value(fn($row) => ...) for computed columns (e.g., full names, formatted dates).
Column::make('Full Name')->value(fn($row) => "{$row->first_name} {$row->last_name}")
Column::make('Status')->view('custom.status-cell')->field('status')
Column::make('Notes')->hiddenOn('sm')
Filter::select('status', 'Status', ['active', 'pending'])
->display('dropdown') // UI mode
->placeholder('All') // Reset option
Filter::text('search', 'Search')
->query(fn($query, $value) => $query->where('name', 'like', "%{$value}%"))
filterToolbarMode('dropdown') in your table class to hide filters by default.ActionColumn::make()->actions([
TableAction::wire('Delete Selected', fn() => $this->bulkDelete(), icon: 'trash'),
]);
ActionColumn::make()->actions([
TableAction::link('Edit', fn($row) => route('users.edit', $row), icon: 'pencil'),
]);
actionBulkDelete() and dispatch openBulkDeleteConfirm events.public function exportColumns(): array {
return [
Column::make('ID')->field('id'),
Column::make('Email')->field('email')->exportable(),
];
}
exportPdfTitle() or exportPdfOrientation() in your table class.defaultSortField() or perPageOptions() for global table behavior.trait SharedFilters {
public function sharedFilters(): array {
return [Filter::select('role', 'Role', ['admin', 'user'])];
}
}
php artisan livewire-table-kit:install-mcp
SKILL.md to generate tables via AI prompts (e.g., "Create a table for Order model with status filters").Flux UI Dependency:
composer require flux/flux) and configured in your project.@import 'flux'; to your CSS if styles are missing.Tailwind Configuration:
content array will break styles.@source in CSS or content: [...] in tailwind.config.js.Generator Overrides:
is_active as a badge when it’s a string).columns() method or override the make:livewire-table stub.Export Dependencies:
composer require maatwebsite/excel barryvdh/laravel-dompdf
Filter Persistence:
use WithPagination, WithSearch, WithFilters; traits from Livewire to manage state.Bulk Delete Confirmation:
openBulkDeleteConfirm event requires a modal component (e.g., Flux’s Modal). Ensure your layout includes it.@livewireScripts and @fluxScripts to your Blade layout.Table Data Not Updating:
query() returns the correct Eloquent builder. Use dd($this->query()->toSql()) to inspect the query.refreshTable events are dispatched correctly (e.g., after filter changes).Filter Not Applying:
key matches the field name in query(). Use dd($this->filters) to debug filter payloads.Export Issues:
storage/logs/laravel.log) for errors like missing fonts.config/excel.php.Styling Problems:
!important if needed (e.g., for BadgeColumn colors).Eager Load Relationships:
with() to your query() to avoid N+1 queries:
public function query() { return User::with('roles')->query(); }
Limit Columns in Exports:
public function exportColumns() { return array_filter($this->columns(), fn($col) => $col->isExportable()); }
Debounce Search:
public function updatedSearch($value) {
$this->debounce(500, fn() => $this->refreshTable());
}
Custom Column Types:
BaseColumn to create specialized columns (e.g., AvatarColumn, ProgressColumn):
class AvatarColumn extends BaseColumn {
public function render($value) { return "<img src='{$value}' class='h-8 w-8'>"; }
}
Dynamic Filter Options:
Filter::select('department', 'Department', fn() => Department::pluck('name', 'id'))
Event Hooks:
refreshTable or notify events in your table class:
protected $listeners = ['refreshTable' => 'logRefresh'];
public function logRefresh() { \Log::info('Table refreshed'); }
Override Views:
resources/views/vendor/livewire-table-kit/...) for custom UI.Localization:
php artisan vendor:publish --tag=livewire-table-kit-lang
resources/lang/en/livewire-table-kit.php.Default Per-Page Options:
perPageOptions() to change pagination defaults (e.g., [5, 10, 20]).Empty State Customization:
How can I help you explore Laravel packages today?