Laravel Scout

Laravel Scout

Introduction

Laravel Scout provides a simple, driver based solution for adding full-text search to your Eloquent models. Using model observers, Scout will automatically keep your search indexes in sync with your Eloquent records.

Currently, Scout ships with an Algolia driver; however, writing custom drivers is simple and you are free to extend Scout with your own search implementations.

Installation

First, install the Scout via the Composer package manager:

1
composer require laravel/scout

Next, you should add the ScoutServiceProvider to the providers array of your config/app.php configuration file:

1
Laravel\Scout\ScoutServiceProvider::class,

After registering the Scout service provider, you should publish the Scout configuration using the vendor:publish Artisan command. This command will publish the scout.php configuration file to your config directory:

1
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"

Finally, add the Laravel\Scout\Searchable trait to the model you would like to make searchable. This trait will register a model observer to keep the model in sync with your search driver:

1
2
3
4
5
6
7
8
9
10
11
<?php
 
namespace App;
 
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;
 
class Post extends Model
{
    use Searchable;
}
doc_Laravel
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.