codewiser/laravel-meilisearch

This package is abandoned and no longer maintained. The author suggests using the codewiser/laravel-scout package instead.

Laravel helper for Meilisearch Scout driver

v1.0.5 2024-04-18 12:50 UTC

This package is auto-updated.

Last update: 2024-04-18 12:55:08 UTC


README

Laravel helper for Meilisearch Scout driver.

Out-of-the-box, we should configure Meiliserach index settings in config/scout.php: https://laravel.com/docs/10.x/scout#configuring-filterable-data-for-meilisearch

use App\Models\User;
use App\Models\Flight;
 
'meilisearch' => [
    'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
    'key' => env('MEILISEARCH_KEY', null),
    'index-settings' => [
        User::class => [
            'filterableAttributes'=> ['id', 'name', 'email'],
            'sortableAttributes' => ['created_at'],
            // Other settings fields...
        ],
        Flight::class => [
            'filterableAttributes'=> ['id', 'destination'],
            'sortableAttributes' => ['updated_at'],
        ],
    ],
],

Using Attributes:

class User extends \Illuminate\Database\Eloquent\Model
{
    use \Laravel\Scout\Searchable;
    
    #[MeilisearchFilterableAttributes(['id', 'name', 'email'])]
    #[MeilisearchSortableAttributes(['created_at'])]
    public function toSearchableArray()
    {
        //
    }
}
class Flight extends \Illuminate\Database\Eloquent\Model
{
    use \Laravel\Scout\Searchable;
    
    #[MeilisearchFilterableAttributes(['id', 'destination'])]
    #[MeilisearchSortableAttributes(['updated_at'])]
    public function toSearchableArray()
    {
        //
    }
}

Just enumerate searchable classes in config/scout.php:

use App\Models\User;
use App\Models\Flight;
 
'meilisearch' => [
    'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
    'key' => env('MEILISEARCH_KEY', null),
    'searchable' => [User::class, Flight::class],
],

Console

Use scout:meilisearch-rebuild command to completely rebuild Meilisearch index.