Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Meilisearch Php Laravel Package

meilisearch/meilisearch-php

Official Meilisearch PHP SDK: a fast, easy API client to index documents, manage settings, and run searches with Meilisearch or Meilisearch Cloud. Supports popular HTTP clients and customizable transport.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer with a PSR-18 HTTP client (e.g., Guzzle):

composer require meilisearch/meilisearch-php guzzlehttp/guzzle http-interop/http-factory-guzzle:^1.0

Ensure Meilisearch is running (locally or via Meilisearch Cloud). Instantiate the client with your instance URL and API key, then create or access an index:

$client = new Client('http://127.0.0.1:7700', 'masterKey');
$index = $client->index('movies');

First use case: Add documents and perform a typo-tolerant search — no prior schema setup required.

Implementation Patterns

  • Index Management: Use $client->createIndex() or access existing indexes via $client->index($uid). Index settings (e.g., filterableAttributes, searchableAttributes) should be configured once via async tasks, then tracked using the returned uid.
  • Document Operations: Batch add/update/delete with addDocuments(), updateDocuments(), deleteDocuments(). Always capture the uid from async operations to poll task status via $index->getTask($uid).
  • Search Flexibility: Use search($query, $options) with filters, pagination, highlighting, and facets. Leverage PHP arrays for complex filters (e.g., ['category = books AND price < 50']).
  • Task Monitoring: Integrate task polling in CLI workers or queues to avoid blocking requests (e.g., Laravel jobs awaiting status === 'succeeded').
  • HTTP Client Customization: Pass a configured PSR-18 client to the Client constructor for timeouts, retries, or middleware (e.g., logging):
    new Client($url, $key, new GuzzleHttpClient(['timeout' => 5.0]));
    

Gotchas and Tips

  • Task-based Workflow: Index updates/settings changes are async. Never assume immediate consistency — check task status before proceeding with dependent operations.
  • Filterable Attributes: Must be explicitly declared before indexing data; updating them triggers index rebuilds. Test in dev first to avoid long rebuild times in production.
  • Exception Handling: In v2.x, custom exceptions are strict and typed. Use $e->getMessage() (not $e->message) and check for specific subclasses like Meilisearch\Exceptions\ApiException.
  • HTTP Client Pitfalls: Ensure PSR-17/18 factories are installed (e.g., nyholm/psr7). Missing factories cause "HTTP Factory not found" errors at runtime.
  • Beta v2.0 Migration: Task methods (e.g., getTasks()) now return typed objects (TaskResults). Update legacy code to use ->getResults() instead of array access.
  • Testing Tip: Use Client::create() with a temporary Meilisearch instance for unit tests; the client’s raw() method helps inspect raw API responses.
  • Performance: For large datasets, prefer addDocumentsInBatches() or deleteDocumentsBy() over bulk operations to avoid timeouts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport