Install the Package & Adapter
composer require cmsig/seal-laravel-package cmsig/seal-elasticsearch-adapter
(Replace elasticsearch-adapter with your preferred adapter, e.g., memory-adapter for testing.)
Publish Configuration
php artisan vendor:publish --provider="CMSIG\SEAL\Laravel\SEALServiceProvider" --tag="seal-config"
Edit config/seal.php to define your adapter and connection settings.
Register the Service Provider
Ensure CMSIG\SEAL\Laravel\SEALServiceProvider::class is in config/app.php under providers.
First Search Query
use CMSIG\SEAL\Laravel\Facades\SEAL;
$results = SEAL::search('query', [
'adapter' => 'elasticsearch', // Matches your config
'index' => 'your_index_name',
]);
config/seal.php (adapter settings, default indices).SEAL::search() for quick queries.Basic Search
$results = SEAL::search('laravel', [
'index' => 'articles',
'limit' => 10,
]);
SEAL::search() for ad-hoc queries.index, limit, offset, or filter.Index Management
// Create/update an index
SEAL::index('products')->addDocument($productData);
// Delete an index
SEAL::deleteIndex('products');
SEAL::index('users')->addDocument($user)).Filtering & Facets
$results = SEAL::search('php', [
'index' => 'posts',
'filter' => ['tags' => ['php', 'laravel']],
'facets' => ['category', 'author'],
]);
filter for boolean constraints (e.g., ['price' => ['>' => 100]]).facets returns aggregated metadata (e.g., top tags).Pagination
$results = SEAL::search('query', [
'index' => 'products',
'limit' => 20,
'offset' => 40, // Page 3
]);
LengthAwarePaginator.Adapter-Specific Features
SEAL::rawQuery() for custom DSL:
$results = SEAL::rawQuery('your_index', [
'body' => ['query' => ['match' => ['title' => 'laravel']]]
]);
search() with SEAL::search() for cross-engine support.public function getSearchResultsAttribute()
{
return SEAL::search($this->title, ['index' => 'products']);
}
SEAL::index('articles')->addDocument($article)->queue();
return response()->json([
'data' => $results->items(),
'meta' => ['total' => $results->total()]
]);
Adapter Mismatch
config/seal.php.adapters array in config matches installed packages. Test with MemoryAdapter first.Index Not Found
SEAL::index('name')->exists() before searching. Auto-create indices if needed:
SEAL::index('dynamic_index')->create();
Case Sensitivity
SEAL::rawQuery() for custom mappings.Rate Limiting
SEAL::search()->retry(3) (if supported).Data Serialization
toArray() or custom serializers:
SEAL::index('users')->addDocument($user->toArray());
config/seal.php:
'log_queries' => env('SEAL_LOG_QUERIES', false),
$raw = SEAL::search('query', ['debug' => true]);
dd($raw->getRawResponse());
curl to verify indices.SEAL::index('name')->getDocuments() for live data.Custom Adapters
CMSIG\SEAL\Adapter\AbstractAdapter to support new engines (e.g., Algolia, Meilisearch).config/seal.php:
'adapters' => [
'custom' => \App\Adapters\CustomAdapter::class,
],
Query Macros
SEAL::macro('searchProducts', function ($query, $limit = 10) {
return $this->search($query, [
'index' => 'products',
'filter' => ['stock' => ['>' => 0]],
'limit' => $limit,
]);
});
Usage: SEAL::searchProducts('shoes').Event Listeners
SEAL.Indexing) for analytics or caching:
SEAL::listen('SEAL.Indexing', function ($event) {
Log::info("Indexing {$event->index} started");
});
Testing
MemoryAdapter for unit tests:
$this->app->singleton('seal', function () {
return SEAL::make('memory');
});
SEAL::deleteIndex('test_index');
config/seal.php under default_adapter. Override per-query:
SEAL::search('query', ['adapter' => 'elasticsearch']);
env() in config:
'elasticsearch' => [
'host' => env('ELASTICSEARCH_HOST', 'localhost'),
],
'adapters' => [
'elasticsearch' => [
'cache' => true,
],
],
How can I help you explore Laravel packages today?