Framework integration / Laravel / Getting started

Requirements

The following versions of PHP and Laravel are required for Scout Extended.

Scout Extended version PHP version Laravel version
3 8.1 and later 10 and later
  8.0 and later 9 and later
2 7.3 and later 8 and later

For Laravel version 6, use version 1 of Scout Extended.

Make sure to read the Scout Extended changelog when upgrading from version 1 to version 2.

Installation

First, install Scout Extended with the Composer package manager:

$
composer require "algolia/scout-extended:^2.0"

If you’re installing Scout Extended in a project that already includes Laravel Scout, you must reimport your data using the php artisan scout:reimport command.

After installing Scout Extended, you should publish the Scout configuration using the php artisan vendor:publish command. This command publishes the scout.php configuration file to your config directory:

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

Lastly, add the Laravel\Scout\Searchable trait to the model you would like to make searchable. This trait registers 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 required, you should use the queue driver for Scout operations. Once you’ve 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

Replace these placeholders in your .env file with your values. You can find them in the Algolia dashboard.

  • <ALGOLIA_APP_ID>. Your Algolia application ID.
  • <ALGOLIA_API_KEY>. Your API key with search and addObject permissions.
$
$
ALGOLIA_APP_ID=<ALGOLIA_APP_ID>
ALGOLIA_SECRET=<ALGOLIA_APP_ID>

Your Admin API key grants full access to your Algolia application. You should never share it with anyone, and it must remain confidential.

Did you find this page helpful?