Before you begin
You need:- An Algolia account
- PHP 8.1 or later
- Laravel 10 or later
Set up the package
Set up the package in a new Laravel app. Then index and search a record.1
Create a Laravel app
To create a new Laravel app, run:
2
Install Scout Extended
To add Scout Extended to your To publish the Scout configuration to your
composer.json file and install it, run:config directory, run:3
Add your credentials
To set Algolia as the Scout driver, add the following lines to your Replace
.env file:.env
ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY with your Algolia credentials.
Find both in the Algolia dashboard.
To run this test, use an API key with the search and addObject ACL.4
Create a model
To create a In the migration file in To create the database table, run:
Contact model and its migration, run:database/migrations,
add a name column to the contacts table:PHP
5
Connect the model to Algolia
To send your model to Algolia, add the
Searchable trait.
Scout Extended stores the model’s records in an named after its table, contacts.Replace the contents of app/Models/Contact.php:app/Models/Contact.php
6
Index and search a record
To add a record, run:Algolia indexes records asynchronously, so wait 5 seconds.
Then, to search for the record, run:If the setup works, the command prints
["Jon Doe"].
Each run of the first command adds another record to your test index.
To remove the test data, delete the index in the Algolia dashboard or with the Algolia CLI.Use a queue driver
Optional: to run Scout operations in the background, configure a queue driver. Then, in yourconfig/scout.php file, set queue to true:
PHP
Import existing data
Choosescout:import or scout:reimport to import your existing data:
- For a new index or an index without live traffic, use
scout:import. This command clears any existing records in the index before importing. - If your existing Laravel Scout project has an Algolia index that serves live traffic, use
scout:reimportto keep search available while you rebuild the index, for example after a significant Scout configuration change.
scout:reimport to ensure everything is in sync.
Scout Extended’s Artisan commands manage index settings and copy, move, and delete indices.
To run them, use an API key with the search, browse, addObject, deleteObject, deleteIndex, editSettings, and settings ACL.
Next steps
- Customize searchable data: control which data Scout Extended indexes
- Server-side search: search your models from Laravel
- Scout Extended changelog: see what changed in each version