Integrations / Frameworks / Laravel / Installation

Installation

Installation

Requires:

First, install Scout Extended via the Composer package manager:

$
composer require algolia/scout-extended

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, it’s highly recommended to 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

You could set your API keys directly inside the scout.php configuration file you just published, but it’s recommended to set the credentials, ALGOLIA_APP_ID and ALGOLIA_SECRET, inside your .env file:

$
$
ALGOLIA_APP_ID=YourApplicationID
ALGOLIA_SECRET=YourAdminAPIKey

Note that your admin API key is sensitive information: it gives full access to your Algolia application. You should never share it with anyone, and it must remain confidential.

Did you find this page helpful?