meilisearch/meilisearch-php
Official PHP client for Meilisearch, the open‑source search engine. Connect to Meilisearch or Meilisearch Cloud to index documents, configure indexes, and run fast, typo‑tolerant searches. Supports customizable HTTP clients and common PHP tooling.
addDocuments() can trigger a job to update search indexes post-Eloquent create()/update()).HttpClient) can be adapted with minimal boilerplate.Model::saved() → Meilisearch::updateDocuments()).cache() facade) or Meilisearch Cloud.belongsTo) may not map cleanly to Meilisearch’s flat document structure. Requires normalization (e.g., JSON fields for relationships).HttpClient (PSR-18 compliant) or Guzzle for flexibility.addDocuments()/updateDocuments() to Laravel queues (e.g., meilisearch:update-index) for async indexing.Cache::remember()) to reduce Meilisearch load.HttpClient mocking or PestPHP to test Meilisearch interactions.WHERE category_id = 1) and Meilisearch for full-text (e.g., title: "action").searchable column to track Meilisearch document IDs for sync.addDocuments() with a one-time dump of existing data (e.g., from Eloquent).// app/Observers/PostObserver.php
public function saved(Post $post) {
Meilisearch::index('posts')->updateDocuments([$post->toSearchableArray()]);
}
DB::select() or Algolia queries with Meilisearch SDK calls.// Replace: DB::select("SELECT * FROM posts WHERE title LIKE '%action%'")
$hits = Meilisearch::index('posts')->search('action')->getHits();
typoTolerance: 'min' in index settings.filterableAttributes for faceted search (e.g., genres = "Action").rankingRules (e.g., prioritize recent posts).CircuitBreaker) to fall back to SQL if Meilisearch fails.composer require meilisearch/meilisearch-php guzzlehttp/guzzle.config/services.php:
'meilisearch' => [
'url' => env('MEILISEARCH_URL', 'http://localhost:7700'),
'api_key' => env('MEILISEARCH_API_KEY'),
'timeout' => 5.0,
],
AppServiceProvider:
$this->app->singleton(Meilisearch\Client::class, function ($app) {
return new Meilisearch\Client(
config('services.meilisearch.url'),
config('services.meilisearch.api_key')
);
});
php artisan meilisearch:create-index posts).// app/Jobs/ImportToMeilisearch.php
public function handle() {
$posts = Post::all()->toSearchableArray();
Meilisearch::index('posts')->addDocuments($posts);
}
updateSearchableAttributes).products_*).distinct in federated search").composer.json to avoid breaking changes (e.g., meilisearch/meilisearch-php:^2.0).$task = $index->addDocuments($documents);
logger()->info("Meilisearch task ID: {$task->uid()}");
getTask() to check status:
$task = $client->getTask($taskId);
if ($task->status() === 'failed') {
throw new \RuntimeException("Meilisearch task failed: " . $task->error());
}
timeout in the client config for slow networks.actions (e.g., documents:*).toSearchableArray() output matches Meilisearch’s schema.products_a, products_b).How can I help you explore Laravel packages today?