Laravel

Install

Install via composer

Add algolia/algoliasearch-laravel to your composer.json file:

composer require algolia/algoliasearch-laravel

Service provider

Add the service provider to config/app.php in the providers array.

<?php
AlgoliaSearch\Laravel\AlgoliaServiceProvider::class

Configure API Keys

Laravel Algolia requires a connection configuration. The package comes with a configuration files where you’ll set your Algolia credentials (applicationID and API Key). Add it to your project with the following command:

php artisan vendor:publish --provider="Vinkla\Algolia\AlgoliaServiceProvider"

This will create a config/algolia.php file in your app that you can modify to set your configuration. You can also create this file manually by copying the file vendor/vinkla/algolia/config/algolia.php to config/algolia.php.

We recommend to use environment specific variables like in the following example:

<?php
return [

    'default' => 'main',

    'connections' => [

        'main' => [
            'id' => env('ALGOLIA_APP_ID'),
            'key' => env('ALGOLIA_API_KEY'),
        ],

    ],

];

And set those value in your .env file.

ALGOLIA_APP_ID='your-application-id'
ALGOLIA_API_KEY='your-api-key'

NOTE: make sure you check for changes compared to the original config file after an upgrade. The original file can be found here vendor/vinkla/algolia/config/algolia.php.

Did you find this page helpful?

We're always looking for advice to help improve our documentation! Please let us know what's working (or what's not!) - we're constantly iterating thanks to the feedback we receive.

Send us your suggestions!