Installation
Algolia Scout Extended requires the following PHP and Laravel versions:
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 |
1 | 7.3 and later | 6 |
For more information, read the Scout Extended changelog.
-
Install Scout Extended with Composer:
Copy$ $
# Install the latest version of Scout Extended composer require "algolia/scout-extended:^3.0"
-
Publish the Scout configuration to your
config
directory:Copy$
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
-
For the model you would like to make searchable, add the
Searchable
trait. For example, for anArticle
model (app/Models/Article.php
):Copy1 2 3 4 5 6 7 8 9
namespace App\Models; use Laravel\Scout\Searchable; use Illuminate\Database\Eloquent\Model; class Article extends Model { use Searchable; }
Replace
Article
with a model used in your app. -
While not required, you should use a queue driver for Scout operations. Once you’ve configured a queue driver, set
queue
totrue
in yourconfig/scout.php
file:Copy1
'queue' => true,
-
To access Algolia, copy your API key values from the Algolia dashboard to your
.env
file:Copy$ $
ALGOLIA_APP_ID=<ALGOLIA_APP_ID> ALGOLIA_SECRET=<ALGOLIA_APP_ID>
<ALGOLIA_APP_ID>
. Your Algolia application ID.<ALGOLIA_API_KEY>
. Your API key withsearch
andaddObject
permissions.
Your Admin API key grants full access to your Algolia application. Don’t share it with anyone: it must remain confidential.
-
You probably have existing data that you would like to import:
- If you’re importing from your Laravel database for the first time, use
scout:import
. - If you’ve installed Scout Extended in a Laravel Scout project, use
scout:reimport
.
If you make significant changes to your Scout configuration or need to reindex all your data, use
scout:reimport
to ensure everything is in sync. - If you’re importing from your Laravel database for the first time, use
-
Open the
routes/web.php
file and add the following route to the bottom of the file:Copy1 2 3 4 5 6 7 8
Route::get('search', function() { $query = ''; // <-- Change the query for testing. // Visit the /search route in your web browser to see articles that match the test $query. $articles = App\Article::search($query)->get(); return $articles; });
Replace
Article
with a model used in your app.