Searchable Columns
To define which resource fields are searchable, you may assign an array of database columns to thesearch
property or searchableColumns
method of your resource class. This array includes the id
column by default:
If you are using Nova’s Scout integration, the
$search
property has no effect on your search results and may be ignored. You should manage the searchable columns within the Algolia or Meilisearch dashboard.Full-Text Indexes
Typically, Nova searches your database columns using simpleLIKE
clauses. However, if you are using MySQL or Postgres, you may take advantage of any full-text indexes you have defined. To do so, you should define a searchableColumns
method on your Nova resource class instead of defining a $search
property.
The searchableColumns
method should return an array of columns that are searchable. You may include an instance of Laravel\Nova\Query\Search\SearchableText
within this array to instruct Nova to utilize your full-text indexes when querying a given column:
app/Nova/Post.php
searchableColumns
method can also include raw SQL expressions, which allow you to search through derived columns:
app/Nova/User.php
Searching Relationships
Laravel Nova also allows you to search against a resource’s related models. For example, imagine aPost
model that is related to a User
model via an author
relatonship. You may indicate that this relationship data should be considered when searching for users by returning an instance of Laravel\Nova\Query\Search\SearchableRelation
from your resource’s searchableColumns
method.
If the searchableColumns
method does not exist on your resource, you should define it. Once the searchableColumns
method has been defined, you may remove the $search
property from your resource:
app/Nova/Post.php
$search
property using “dot notation”:
app/Nova/Post.php
MorphTo Relationships
“Morph to” relationships can be made searchable by returning an instance ofLaravel\Nova\Query\Search\SearchableMorphToRelation
from your resource’s searchableColumns
method. The SearchableMorphToRelation
class allows you to specify which types of morphed models should be searched:
app/Nova/~Resource.php
Searching JSON Data
If the database table associated with your resource includes a column that contains a JSON string, you may instruct Nova to search within the JSON string by returning aLaravel\Nova\Query\Search\SearchableJson
instance from your resource’s searchableColumns
method.
If the searchableColumns
method does not exist on your resource, you should define it. Once the searchableColumns
method has been defined, you may remove the $search
property from your resource:
app/Nova/UserProfile.php