- Can I use this package directly in Laravel without Scout, or is Scout required?
- This is a low-level client and works independently of Laravel Scout. Use it for custom logic like bulk indexing, advanced queries, or hybrid search workflows. For Eloquent model integration, pair it with `algolia/scout-extended` to replace Scout’s default driver.
- What Laravel versions support this package, and how does it integrate with Scout?
- The package requires PHP 8.0+, compatible with Laravel 8.1+. For Scout integration, use `algolia/scout-extended` (v2.0+) to replace the default Scout driver. The base client remains agnostic to Laravel’s ORM but works seamlessly with Scout’s event hooks.
- How do I handle API key rotation securely in Laravel?
- Store your Algolia API keys in Laravel’s `.env` file (e.g., `ALGOLIA_APP_ID`, `ALGOLIA_API_KEY`). For production, use Laravel’s `config/cache` or a secrets manager like HashiCorp Vault. Rotate keys by updating the environment variables and restarting queue workers if using async indexing.
- Does this client support real-time indexing for Laravel models?
- Yes, but requires manual setup. Use Laravel events (e.g., `ModelSaved`) to trigger `saveObject` calls via a queue job. For webhook-based real-time sync, use Algolia’s Ingestion API with the client’s `waitForTask` method to poll task completion.
- What are the breaking changes in recent versions (e.g., 4.42.0), and how do I migrate?
- Version 4.42.0 introduced breaking changes to the Composition API and `SearchResponse` model. Audit the [changelog](https://github.com/algolia/algoliasearch-client-php/blob/master/CHANGELOG.md) and update your code to use the new response structure. Test multi-index queries and rule-based personalization if applicable.
- How do I optimize search performance for high-traffic Laravel apps?
- Leverage Algolia’s `hitsPerPage` and faceting for faster queries. For indexing, use batch operations (`saveObjects`) and Laravel queues to offload heavy workloads. Monitor latency with Algolia’s Insights API, and cache frequent queries using Laravel’s cache drivers.
- Can I use this client with Laravel’s service container for dependency injection?
- Yes, bind the `SearchClient` to Laravel’s IoC container in `config/app.php` or a service provider. Example: `app()->bind(SearchClient::class, fn() => SearchClient::create(env('ALGOLIA_APP_ID'), env('ALGOLIA_API_KEY')));`. This enables clean DI in controllers and services.
- What alternatives exist for Algolia in Laravel, and when should I consider them?
- For simpler use cases, Laravel Scout’s built-in Algolia driver suffices. For open-source alternatives, consider Meilisearch (via `meilisearch/meilisearch-php`) or Typesense. Use this client only if you need Algolia’s advanced features like Rules, Insights, or Composition API.
- How do I handle Algolia API rate limits in Laravel queue jobs?
- Configure the client’s `RetryStrategy` to handle rate limits gracefully. For queue jobs, implement exponential backoff using Laravel’s `retryAfter` or a custom retry logic wrapper. Monitor queue failures and adjust batch sizes to avoid hitting limits.
- Does this client support caching, and how does it integrate with Laravel’s cache drivers?
- The client supports caching responses via a `Cache` directory, but Laravel’s cache drivers (Redis, file) must be configured manually. Use Laravel’s cache facade to store and retrieve search results, e.g., `Cache::remember('search_results', 60, fn() => $client->search(...));`