lee-to/moonshine-algolia-search

Algolia global search for MoonShine

1.0.0 2023-05-02 15:37 UTC

This package is auto-updated.

Last update: 2024-03-31 17:41:49 UTC


README

Algolias search for MoonShine

As a result, all menu items will be indexed, including groups, resources, resource entries and custom pages

Installation

composer require lee-to/moonshine-algolia-search

Publish config

php artisan vendor:publish --provider="Leeto\MoonShineAlgoliaSearch\Providers\MoonShineAlgoliaSearchServiceProvider"

Register on the https://www.algolia.com, get the keys and set in config config/algolia.php

return [
    'app_id' => env('ALGOLIA_APP_ID'),
    'admin_key' => env('ALGOLIA_ADMIN_KEY'),
    'frontend_key' => env('ALGOLIA_FRONTEND_KEY'),
];

MoonShine config (app/moonshine.php)

// ...
'header' => 'algolia-search::global-search'
// ...

Create indexes

php artisan algolia-search:indexes

If you want to customize fields for models, implement the HasGlobalAlgoliaSearch interface

use Illuminate\Database\Eloquent\Model;
use Leeto\MoonShineAlgoliaSearch\Contracts\HasGlobalAlgoliaSearch;

class Post extends Model implements HasGlobalAlgoliaSearch
{
    public function globalSearch(): array
    {
        return [
            'description' => $this->text,
            'image' => $this->thumbnail
        ];
    }
}