Integrations / Frameworks / Laravel / Installation

Installation

Installation

Requires:

First, install Scout Extended via the Composer package manager:

$
composer require algolia/scout-extended

If you are installing Scout Extended in a project that already contains Laravel Scout, you must re-import your data using the scout:reimport Artisan command.

After installing Scout Extended, 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 Algolia:

1
2
3
4
5
6
7
8
9
namespace App;

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

class Article extends Model
{
    use Searchable;
}

While not strictly required, we strongly advise you to use the Queue driver for Scout operations. Once you have configured a queue driver, set the value of the queue option in your config/scout.php configuration file to true:

1
'queue' => true,

Configure API Keys

You can set the keys directly inside the scout.php file that we just published but we recommend rather that you set the credentials, APP_ID and API Key, inside the .env file by adding the following content:

$
$
ALGOLIA_APP_ID=YourApplicationID
ALGOLIA_SECRET=YourAdminAPIKey

Note that your Admin API key is very sensitive: it should never be shared with anyone and must remain confidential.

Did you find this page helpful?