This guide will walk you through creating a fully functional data table with search, sorting, filtering, pagination, and bulk actions. By the end, you’ll have a production-ready table component.
This tutorial assumes you have already installed Laravel Livewire Tables.
For Tailwind CSS users, add this CSS rule to prevent Alpine.js flicker:
[x-cloak] { display: none !important; }
2
Generate a Table Component
Use the Artisan command to generate a new table component. The command accepts two arguments: the table name and the model name.
php artisan make:livewiretable UsersTable User
This creates a file at app/Livewire/Tables/UsersTable.php with auto-detected columns from your database schema.
The generator automatically introspects your database table and creates columns based on the schema. It skips sensitive fields like password and remember_token.
Generate in a subdirectory:
php artisan make:livewiretable Admin/UsersTable User
3
Review the Generated Code
Here’s what the generator creates for a User model:
<?phpnamespace App\Livewire\Tables;use App\Models\User;use Illuminate\Database\Eloquent\Builder;use Livewire\Tables\Columns\BooleanColumn;use Livewire\Tables\Columns\TextColumn;use Livewire\Tables\Filters\BooleanFilter;use Livewire\Tables\Livewire\DataTableComponent;class UsersTable extends DataTableComponent{ public function configure(): void { $this->setDefaultPerPage(10); } public function query(): Builder { return User::query(); } public function columns(): array { return [ TextColumn::make('name') ->label('Name') ->sortable() ->searchable(), TextColumn::make('email') ->label('Email') ->sortable() ->searchable(), ]; } public function filters(): array { return [ // Add filters here ]; }}
The query() method returns an Eloquent Builder, so you can add eager loading, scopes, or joins as needed.
4
Use the Table in a Blade View
Render the table component in any Blade template:
<livewire:tables.users-table />
Or with a fully qualified name:
@livewire('tables.users-table')
5
See the Result
Visit the page in your browser. You’ll see a fully functional data table with: