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:

composer require laravel/scout

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

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:

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:

<?php

namespace App;

use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use Searchable;
}
doc_Laravel
2016-11-02 16:23:25
Comments
Leave a Comment

Please login to continue.