Skip to content

Conversation

@JustSteveKing
Copy link
Contributor

Every now and then (admittedly not very often) you might have different models registered on different search engines. This PR adds to the scout docs explaining how to override on a model basis the engine it is using - removing the need for hot swapping configuration at runtime.

<?php

 namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\EngineManager;
use Laravel\Scout\Searchable;

class User extends Model
{
    use Searchable;

    /**
     * Get the value used to index the model.
     *
     * @return \Laravel\Scout\Engines\Engine
     */
    public function searchableUsing()
    {
        return app(EngineManager::class)->engine('meilisearch');
    }
}

@taylorotwell taylorotwell merged commit 74c9577 into laravel:9.x May 24, 2022
@JustSteveKing JustSteveKing deleted the scout-model-engine-swapping branch May 25, 2022 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants