DeveloperBreeze

Dynamic Filtering Development Tutorials, Guides & Insights

Unlock 1+ expert-curated dynamic filtering tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your dynamic filtering skills on DeveloperBreeze.

Implementing Real-Time Search with Livewire in Laravel

Tutorial August 14, 2024
javascript php

Open the newly created SearchPosts.php file and set up the properties and methods to manage the search query and results:

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Post;

class SearchPosts extends Component
{
    public $query = '';
    public $posts = [];

    public function updatedQuery()
    {
        $this->posts = Post::where('title', 'like', '%' . $this->query . '%')->get();
    }

    public function render()
    {
        return view('livewire.search-posts');
    }
}