malambart's avatar

Laravel Scout: use more than one driver?

Hello all,

Is it possible to use for example, Algolia to search some models and another driver, lets say Mysql fulltext, to search another model? I can't find anything in the docs.

Thanks a lot

0 likes
2 replies
lara30453's avatar
Level 6

Using the config() helper. You can set the driver to MySQL in a controller action before doing anything. Then, in another controller you can use your default Scout driver.

1 like
malambart's avatar

Nice one. So I can create a method in my model class that overwrite Search like this:

static function mySqlSearch($string) {
        config(['scout.driver' => 'mysql']);
        return static::search($string);
    }

and in my controller, to prevent models to be indexed in Algolia, I can use the same trick:

public function store(Request $request)
    {
        config(['scout.driver' => 'mysql']);
        myModel::create($request->all());
}

It is not super clean, but it gets the job done :-)

Please or to participate in this conversation.