https://livewire.laravel.com is a fantastic package for creating interactive interfaces in a Laravel app. Using Livewire, you can write component classes that define interactive behavior.
We will work with a straightforward Livewire component to search for quotes in the database. Here's what that component could look like: namespace App\Http\Livewire; use App\Models\Quote; use Illuminate\Support\Collection; use Livewire\Component; class SearchComponent extends Component { public string $searchingFor = ''; public function render() { return view('livewire.search', [ 'quotes' => $this->getQuotes()]); } public function getQuotes(): Collection { if (empty($this->searchingFor)) { return collect(); } return Quote::search($this->searchingFor); }}
public function render() { ray($this->searchingFor); return view('livewire.search', [ 'quotes' => $this->getQuotes()]); }