Defining Searchable Columns 0:00We already defined some searchable columns in our post resource in Nova. But let's take a deeper look and find out how it works and how we can manipulate the search results. So for our post resource, we have this search array, and in there we define that we want the ID, the title, and the body to be searchable. So to give this a try, if I search for 3, it will only return the entry with the ID 3, and if I search for something like 3rd, we will also only find the post that contains this string in one of the three columns. So by default, Nova will just search through all of these columns that you add here when you do the searching on the index page. Using Index and Global Search 0:44So by default, Nova will just search through all of these columns that you add here when you do the searching on the index page. If you don't want the search to be available at all, you can just return an empty array here, reload the page, and the search field is gone. In addition to the searching on the index page, Nova also ships with a global search, which allows us to basically search on the top here for all our resources. So if I search for 1, this will now look up all my resources, they all have the ID searchable, and now I see that this is the post with the ID 1, this is the tag with the ID 1, and this is the user with the ID 1. Let's take a look at how we can modify this result so that this says something else. Customizing Global Result Title 1:32is the user with the ID 1. Let's take a look at how we can modify this result so that this says something else. So for our post, maybe I want to display the title of the post, but also the category, and maybe also the user that created this blog post. Since our post resource has this title attribute which defines what we will see when we search for this, it's not that easy to overwrite and do things like combine two columns together. To do this, you can just get rid of this title string, and use a method instead. So instead we can do something like public function title, and in here I'm going to return this title, and maybe like a dash, and then this category. Now if I search again, we will now see that this returns the title of the post, and then Adding a Result Subtitle 2:22this title, and maybe like a dash, and then this category. Now if I search again, we will now see that this returns the title of the post, and then we have the dash and the category of the post. So by defining a custom title function, we can combine multiple attributes and make use of PHP in our title. To define a subtitle, it's easy. So we just define a new method, call it subtitle, and in here we can return another string. So to display the username that wrote this blog post, we can do return this username, and maybe in here we say author, so that you know what this means. And as you can see, we now have the title combined with the category, and underneath Disabling Global Search per Resource 3:14and maybe in here we say author, so that you know what this means. And as you can see, we now have the title combined with the category, and underneath it we have a nice subtitle that shows us what the author of this specific post is. In addition, if you want to disable global search for one or multiple of your resources, you can overwrite a globally searchable property on your resource. So if we go in here and define public static globally searchable and set it to false, and then we search again for one, our posts no longer show up. So out of the box, Nova searches by using SQL or, well, the database that you use. The only downside of this is that you don't have fuzzy search or any other support that some bigger search engines like Algolia give you. Enabling Fuzzy Search with Scout 4:18The only downside of this is that you don't have fuzzy search or any other support that some bigger search engines like Algolia give you. So for example, if I search for something like Frist, so I have a typo in Frist, well it won't show anything because this is not the exact string that is in our database. To make use of something like Algolia, we can make use of Laravel Scout. So Laravel Scout allows us to use search engines for our models, and all we have to do to make this work with Laravel Nova is we have to enable the searchable trait on our models. So if we go to the post model and enable Scout for this, all we have to do is say use searchable, import the trait, and if we now go back and I type Frist, we can now find the specific post.searchable, import the trait, and if we now go back and I type Frist, we can now find the specific post. In order to make this work, you first need to install Laravel Scout, of course, which I already did, and you have to import your models to Algolia. But once you have done this, all you need to do is add this searchable trait, and then Nova will pick it up and use this for your model searching. And you can also combine this. So for example, the post model now uses Algolia for the search, but my user model doesn't. And if I go back to the resource and enable the global searching, and we go back to Nova, we can do both.And if I go back to the resource and enable the global searching, and we go back to Nova, we can do both. So I can still search for my user, and if I now search globally using the typo, it will use Algolia in the back to find my specific post.