Livewire Data Tables Pattern
January 16, 2026
•
1 min read
•
21 views
Data table component:
Component
class UsersTable extends Component
{
#[Url]
public $search = '';
#[Url]
public $sortBy = 'name';
#[Url]
public $sortDir = 'asc';
public function sort($column)
{
if ($this->sortBy === $column) {
$this->sortDir = $this->sortDir === 'asc' ? 'desc' : 'asc';
} else {
$this->sortBy = $column;
$this->sortDir = 'asc';
}
}
}
Query
#[Computed]
public function users()
{
return User::query()
->when($this->search, fn($q) => $q->where('name', 'like', "%{$this->search}%"))
->orderBy($this->sortBy, $this->sortDir)
->paginate(10);
}
Related Posts
Laravel Sanctum API Authentication Complete Guide
Build secure API authentication with Laravel Sanctum for SPAs and mobile apps.
Laravel Rate Limiting: Protect Your Application
Implement rate limiting to protect your Laravel application from abuse.
Laravel Blade Components: Build Reusable UI
Create powerful reusable components with Laravel Blade.
Comments (0)
No comments yet. Be the first to comment!