How to disable Laravel Scout for Nova Resources

April 19th, 2024

For whatever reason, you may need to disable Laravel Nova automatically using Scout when searching. Here's how.

By default, if Nova detects you're using Laravel Scout on a model (with the Searchable trait), it'll use this internally to perform searches.

There are a couple of reasons you might not want this to happen:

  1. You don't want to use up search quota in the service you're using (in my case, Algolia)
  2. In a development environment, you may not have everything indexed, so using Nova will depend on these items being within an index

It's a pretty quick fix! Just add the usesScout method to the Nova resource you want to control Scout for, and return false.

class Course extends Resource
{
    public static $search = [
        'id', 'title', 'slug'
    ];
    
    public static function usesScout()
    {
        return false;
    }
    
    //...
}

And that's it! Laravel Scout will now be disabled for that resource, and the search results will be performed directly from your database.

Thanks for reading! If you found this article helpful, you might enjoy our practical screencasts too.
Author
Alex Garrett-Smith
Share :

Comments

No comments, yet. Be the first to leave a comment.

Table of contents

Tagged under