-
composer.json
Open in GitHub{ // "require": { "php": "^8.0", "algolia/algoliasearch-client-php": "^2.7", // "laravel/scout": "^8.3" }, // }
-
app/Models/Post.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; use Laravel\Scout\Searchable; class Post extends Model { use Searchable; // public function toSearchableArray(): array { if (! $this->published) { return []; } $postAttributes = $this->toArray(); unset($postAttributes['text']); return $postAttributes; } // }
-
app/Http/Livewire/SearchComponent.php
Open in GitHubuse App\Models\Post; use Illuminate\Support\Collection; use Livewire\Component; class SearchComponent extends Component { public string $query = ''; public function render() { return view('livewire.search', [ 'results' => $this->getResults(), ]); } public function getResults(): Collection { if ($this->query === '') { return collect(); } return Post::search($this->query)->take(30)->get(); } }