{"id":13396192,"url":"https://github.com/algolia/algoliasearch-laravel","last_synced_at":"2026-01-14T01:34:59.296Z","repository":{"id":31604712,"uuid":"35169633","full_name":"algolia/algoliasearch-laravel","owner":"algolia","description":"[Deprecated] We now recommend using Laravel Scout, see =\u003e ","archived":true,"fork":false,"pushed_at":"2018-03-05T13:40:29.000Z","size":170,"stargazers_count":238,"open_issues_count":0,"forks_count":52,"subscribers_count":81,"default_branch":"master","last_synced_at":"2025-11-27T14:32:32.874Z","etag":null,"topics":["algolia-search","laravel","php","search-engine"],"latest_commit_sha":null,"homepage":"https://www.algolia.com/doc/api-client/laravel/install/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/algolia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-06T16:16:29.000Z","updated_at":"2024-07-22T14:41:44.000Z","dependencies_parsed_at":"2022-08-26T10:01:12.229Z","dependency_job_id":null,"html_url":"https://github.com/algolia/algoliasearch-laravel","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/algolia/algoliasearch-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Falgoliasearch-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Falgoliasearch-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Falgoliasearch-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Falgoliasearch-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/algolia","download_url":"https://codeload.github.com/algolia/algoliasearch-laravel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/algolia%2Falgoliasearch-laravel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algolia-search","laravel","php","search-engine"],"created_at":"2024-07-30T18:00:42.190Z","updated_at":"2026-01-14T01:34:59.274Z","avatar_url":"https://github.com/algolia.png","language":"PHP","funding_links":[],"categories":["Popular Packages"],"sub_categories":[],"readme":"# [DEPRECATED] Algolia Search API Client for Laravel\n\n[Algolia Search](https://www.algolia.com) is a hosted full-text, numerical, and faceted search engine capable of delivering realtime results from the first keystroke.\n\n---\n\n**This package is deprecated, we recommend you to use [Laravel Scout](https://laravel.com/docs/5.4/scout)**. If you want to extend Scout capabilities, please refer to [our dedicated documentation](https://www.algolia.com/doc/api-client/laravel/algolia-and-scout/)\n\n---\n\n[![Build Status](https://img.shields.io/travis/algolia/algoliasearch-laravel/master.svg?style=flat)](https://travis-ci.org/algolia/algoliasearch-laravel)\n[![Latest Version](https://img.shields.io/github/release/algolia/algoliasearch-laravel.svg?style=flat)](https://github.com/algolia/algoliasearch-laravel/releases)\n[![License](https://img.shields.io/packagist/l/algolia/algoliasearch-laravel.svg?style=flat)](https://packagist.org/packages/algolia/algoliasearch-laravel)\n\n\nThis PHP package integrates the Algolia Search API into the Laravel Eloquent ORM. It's based on the [algoliasearch-client-php](https://github.com/algolia/algoliasearch-client-php) package.\n\n**Note:** If you're using Laravel 4, checkout the [algoliasearch-laravel-4](https://github.com/algolia/algoliasearch-laravel-4) repository.\n\n\n\n\n## API Documentation\n\nYou can find the full reference on [Algolia's website](https://www.algolia.com/doc/api-client/laravel/).\n\n\n## Table of Contents\n\n\n1. **[Install](#install)**\n\n    * [Install via composer](#install-via-composer)\n    * [Service provider](#service-provider)\n    * [Publish vendor](#publish-vendor)\n\n1. **[Quick Start](#quick-start)**\n\n    * [Quick Start](#quick-start)\n    * [Ranking \u0026amp; Relevance](#ranking--relevance)\n    * [Frontend Search (realtime experience)](#frontend-search-realtime-experience)\n    * [Backend Search](#backend-search)\n\n1. **[Options](#options)**\n\n    * [Auto-indexing \u0026amp; Asynchronism](#auto-indexing--asynchronism)\n    * [Custom Index Name](#custom-index-name)\n    * [Per-environment Indexes](#per-environment-indexes)\n    * [Custom `objectID`](#custom-objectid)\n    * [Restrict Indexing to a Subset of Your Data](#restrict-indexing-to-a-subset-of-your-data)\n\n1. **[Relationships](#relationships)**\n\n    * [Relationships](#relationships)\n\n1. **[Indexing](#indexing)**\n\n    * [Manual Indexing](#manual-indexing)\n    * [Manual Removal](#manual-removal)\n    * [Reindexing](#reindexing)\n    * [Clearing an Index](#clearing-an-index)\n\n1. **[Manage indices](#manage-indices)**\n\n    * [Primary/Replica](#primaryreplica)\n    * [Target Multiple Indexes](#target-multiple-indexes)\n\n1. **[Eloquent compatibility](#eloquent-compatibility)**\n\n    * [Eloquent compatibility](#eloquent-compatibility)\n    * [Compatibility](#compatibility)\n\n\n\n\n# Install\n\n\n\n## Install via composer\nAdd `algolia/algoliasearch-laravel` to your `composer.json` file:\n\n```bash\ncomposer require algolia/algoliasearch-laravel\n```\n\n## Service provider\nAdd the service provider to `config/app.php` in the `providers` array.\n\n```php\nAlgoliaSearch\\Laravel\\AlgoliaServiceProvider::class\n```\n\n## Publish vendor\n\nLaravel Algolia requires a connection configuration. To get started, you'll need to publish all vendor assets:\n\n```bash\nphp artisan vendor:publish\n```\n\nYou can add the ```--provider=\"Vinkla\\Algolia\\AlgoliaServiceProvider\"``` option to only publish assets of the Algolia package.\n\nThis will create a `config/algolia.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes compared to the original config file after an upgrade.\n\n\n# Quick Start\n\n\n\n## Quick Start\n\nThe following code adds search capabilities to your `Contact` model creating a `Contact` index:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse AlgoliaSearch\\Laravel\\AlgoliaEloquentTrait;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n}\n```\n\nBy default all visible attributes are sent. If you want to send specific attributes you can do something like:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public function getAlgoliaRecord()\n    {\n        return array_merge($this-\u003etoArray(), [\n            'custom_name' =\u003e 'Custom Name'\n        ]);\n    }\n}\n```\n\nAfter setting up your model, you need to manually do an initial import of your data. You can do this by calling `reindex` on your model class. Using our previous example, this would be:\n\n```php\nContact::reindex();\n```\n\n## Ranking \u0026 Relevance\n\nWe provide many ways to configure your index settings to tune the overall relevancy, but the most important ones are the **searchable attributes** and the attributes reflecting the **record popularity**. You can configure them with the following code:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public $algoliaSettings = [\n        'searchableAttributes' =\u003e [\n            'id',\n            'name',\n        ],\n        'customRanking' =\u003e [\n            'desc(popularity)',\n            'asc(name)',\n        ],\n    ];\n}\n```\n\nYou can propagate (save) the settings to algolia by using the `setSetting` method:\n\n```php\nContact::setSettings();\n```\n\n#### Synonyms\n\nSynonyms are used to tell the engine about words or expressions that should be considered equal in regard to the textual relevance.\n\nOur [synonyms API](https://www.algolia.com/doc/relevance/synonyms) has been designed to manage as easily as possible a large set of synonyms for an index and its replicas.\n\nYou can use the synonyms API by adding a `synonyms` in `$algoliaSettings` class property like this:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public $algoliaSettings = [\n        'synonyms' =\u003e [\n            [\n                'objectID' =\u003e 'red-color',\n                'type'     =\u003e 'synonym',\n                'synonyms' =\u003e ['red', 'another red', 'yet another red']\n            ]\n        ]\n    ];\n}\n```\n\nYou can propagate (save) the settings to algolia using the `setSetting` method:\n\n```php\nContact::setSettings();\n```\n\n## Frontend Search (realtime experience)\n\nTraditional search implementations tend to have search logic and functionality on the backend. This made sense when the search experience consisted of a user entering a search query, executing that search, and then being redirected to a search result page.\n\nImplementing search on the backend is no longer necessary. In fact, in most cases it is harmful to performance because of the extra network and processing latency. We highly recommend the usage of our [JavaScript API Client](https://github.com/algolia/algoliasearch-client-javascript) issuing all search requests directly from the end user's browser, mobile device, or client. It will reduce the overall search latency while offloading your servers at the same time.\n\nIn your JavaScript code you can do:\n\n```js\nvar client = algoliasearch('ApplicationID', 'Search-Only-API-Key');\nvar index = client.initIndex('YourIndexName');\nindex.search('something', function(success, hits) {\n  console.log(success, hits)\n}, { hitsPerPage: 10, page: 0 });\n```\n\n## Backend Search\n\nYou could also use the `search` method, but it's not recommended to implement an instant/realtime search experience from the backend (having a frontend search gives a better user experience):\n\n```php\nContact::search('jon doe');\n```\n\n\n# Options\n\n\n\n## Auto-indexing \u0026 Asynchronism\n\nEach time a record is saved; it will be - asynchronously - indexed. On the other hand, each time a record is destroyed, it will be - asynchronously - removed from the index.\n\nYou can disable the auto-indexing and auto-removing by setting the following options:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public static $autoIndex = false;\n    public static $autoDelete = false;\n}\n```\n\nYou can temporarily disable auto-indexing. This is often done for performance reasons.\n\n```php\nContact::$autoIndex = false;\nContact::clearIndices();\n\nfor ($i = 0; $i \u003c 10000; $i++) {\n    $contact = Contact::firstOrCreate(['name' =\u003e 'Jean']);\n}\n\nContact::reindex(); // Will use batch operations.\nContact::$autoIndex = true;\n```\n\nYou can also make a dynamic condition for those two parameters by creating an `autoIndex` and/or `autoDelete method`\non your model\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public function autoIndex()\n    {\n        if (\\App::environment() === 'test') {\n            return false;\n        }\n\n        return true;\n    }\n\n    public static autoDelete()\n    {\n        if (\\App::environment() === 'test') {\n            return false;\n        }\n\n        return true;\n    }\n}\n```\n\nBe careful to define those two methods in AlgoliaEloquentTrait.\nWhen putting those methods in a parent class they will be \"erased\" by AlgoliaEloquentTrait if used in a child class\n(because of php inheritance).\n\n## Custom Index Name\n\nBy default, the index name will be the pluralized class name, e.g. \"Contacts\". You can customize the index name by using the `$indices` option:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public $indices = ['contact_all'];\n}\n```\n\n## Per-environment Indexes\n\nYou can suffix the index name with the current App environment using the following option:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public static $perEnvironment = true; // Index name will be 'Contacts_{\\App::environnement()}';\n}\n```\n\n## Custom `objectID`\n\nBy default, the `objectID` is based on your record's `keyName` (`id` by default). You can change this behavior specifying the `objectIdKey` option (be sure to use a uniq field).\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public static $objectIdKey = 'new_key';\n}\n```\n\n## Restrict Indexing to a Subset of Your Data\n\nYou can add constraints controlling if a record must be indexed by defining the `indexOnly()` method.\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public function indexOnly($index_name)\n    {\n        return (bool) $condition;\n    }\n}\n```\n\n\n# Relationships\n\n\n\n## Relationships\n\nBy default the Algolia package will fetch the **loaded** relationships.\n\nIf you want to index records that haven't yet loaded any relations, you can do it by loading them in the ```getAlgoliaRecord``` that you can create in your model.\n\nIt will look like:\n\n```php\npublic function getAlgoliaRecord()\n{\n    /**\n     * Load the categories relation so that it's available\n     *  in the laravel toArray method\n     */\n    $this-\u003ecategories;\n\n   return $this-\u003etoArray();\n}\n```\n\nIn the resulted object, you will have categories converted to array by Laravel. If you want a custom relation structure you will instead do something like:\n\n```php\npublic function getAlgoliaRecord()\n{\n    /**\n     * Load the categories relation so that it's available\n     *  in the laravel toArray method\n     */\n    $extra_data = [];\n    $extra_data['categories'] = array_map(function ($data) {\n                                        return $data['name'];\n                                }, $this-\u003ecategories-\u003etoArray());\n\n   return array_merge($this-\u003etoArray(), $extra_data);\n}\n```\n\n\n# Indexing\n\n## Visibility\n\nBy default, Algolia will only be able to access **visible** attributes of your model. So, for example, you will receive a `No content in PUT request` exception when using this example code, because `invisible_attribute` key returns an empty/null variable.\n\n```php\nprotected $visible = ['visible_attribute', 'other_visible_attribute'];\n\npublic function getAlgoliaRecord()\n{\n    return [\n        'invisible_attribute' =\u003e $this-\u003einvisible_attribute\n    ];\n}\n```\n\nBefore Indexing, be sure to have correctly listed your visible attributes. To bypass this safety mask imposed by Laravel, you may use `$this-\u003eattributes['invisible_attribute']` to access directly to the attribute even if is not visible, but the recommendation is to avoid this type of access to attributes in your Model.\n\n## Manual Indexing\n\nYou can trigger indexing using the `pushToIndex` instance method.\n\n```php\n$contact = Contact::firstOrCreate(['name' =\u003e 'Jean']);\n$contact-\u003epushToIndex();\n```\n\n## Manual Removal\n\nAnd trigger the removal using the `removeFromIndex` instance method.\n\n```php\n$contact = Contact::firstOrCreate(['name' =\u003e 'Jean']);\n$contact-\u003eremoveFromIndex();\n```\n\n## Reindexing\n\nTo *safely* reindex all your records (index to a temporary index + move the temporary index to the current one atomically), use the `reindex` class method:\n\n```php\nContact::reindex();\n```\n\nTo reindex all your records (in place, without deleting outdated records):\n\n```php\nContact::reindex(false);\n```\n\nTo set settings during the reindexing process:\n\n```php\nContact::reindex(true, true);\n```\n\nTo keep settings that you set on the Algolia dashboard when reindexing and changing settings:\n\n```php\nContact::reindex(true, true, true);\n```\n\nTo implement a callback that gets called everytime a batch of entities is indexed:\n\n```php\nContact::reindex(true, true, false, function ($entities)\n{\n    foreach ($entities as $entity)\n    {\n        var_dump($entity-\u003eid); // Contact::$id\n    }\n});\n```\n\n## Clearing an Index\n\nTo clear an index, use the `clearIndices` class method:\n\n```ruby\nContact::clearIndices();\n```\n\n# Manage indices\n\n\n\n## Primary/Replica\n\nYou can define replica indexes using the `$algolia_settings` variable:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n     use AlgoliaEloquentTrait;\n\n     public $algoliaSettings = [\n        'searchableAttributes' =\u003e [\n            'id',\n            'name',\n        ],\n        'customRanking' =\u003e [\n            'desc(popularity)',\n            'asc(name)',\n        ],\n        'replicas' =\u003e [\n            'contacts_desc',\n        ],\n    ];\n\n    public $replicasSettings = [\n        'contacts_desc' =\u003e [\n            'ranking' =\u003e [\n                'desc(name)',\n                'typo',\n                'geo',\n                'words',\n                'proximity',\n                'attribute',\n                'exact',\n                'custom'\n            ]\n        ]\n    ];\n}\n```\n\nTo search using a replica, use the following code:\n\n```php\nBook::search('foo bar', ['index' =\u003e 'contacts_desc']);\n```\n\n## Target Multiple Indexes\n\nYou can index a record in several indexes using the \u003ccode\u003e$indices\u003c/code\u003e property:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Contact extends Model\n{\n    use AlgoliaEloquentTrait;\n\n    public $indices = [\n        'contact_public',\n        'contact_private',\n    ];\n\n    public function indexOnly($indexName)\n    {\n        if ($indexName == 'contact_public')\n            return true;\n\n        return $this-\u003eprivate;\n    }\n\n}\n```\n\nTo search using an extra index, use the following code:\n\n```php\nBook::search('foo bar', ['index' =\u003e 'contacts_private']);\n```\n\n\n# Eloquent compatibility\n\n\n\n## Eloquent compatibility\n\nDoing:\n\n```php\nAd::where('id', $id)-\u003eupdate($attributes);\n```\n\nwill not trigger anything in the model (so no update will happen in Algolia). This is because it is not an Eloquent call. It is just a convenient way to generate the query hidden behind the model.\n\nTo make this query work with Algolia you need to do it like this:\n\n```php\nAd::find($id)-\u003eupdate($attributes);\n```\n\n## Compatibility\n\nCompatible with 5.x applications\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Falgoliasearch-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falgolia%2Falgoliasearch-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falgolia%2Falgoliasearch-laravel/lists"}