Livewire Autocomplete Search
January 16, 2026
•
1 min read
•
13 views
Autocomplete search:
Component
public string $search = '';
public ?User $selected = null;
#[Computed]
public function results()
{
if (strlen($this->search) < 2) return [];
return User::where('name', 'like', "%{$this->search}%")
->limit(5)->get();
}
public function select(User $user)
{
$this->selected = $user;
$this->search = $user->name;
}
View
@foreach($this->results as $user)
-
{{ $user->name }}
@endforeach
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!