In addition to searching in the table or the column, Filament offers a so-called "Global search" in multiple Models. It's very simple to activate so this lesson will be pretty short.
To enable that search, you don't have to configure it at all. Instead, you just specify searchable properties in each Resource you need.
For example, you want Filament to search for Products by their names. You just add a property $recordTitleAttribute
into the Resource:
app/Filament/Resources/ProductResource.php:
class ProductResource extends Resource{ protected static ?string $recordTitleAttribute = 'name';
And that's it: on the top-right, you will see a search showing the products by name.
If you click on the search result, you will go to that resource's Edit page. If you want to change that to a View page, for example, you need to specify this method:
app/Filament/Resources/ProductResource.php:
use Illuminate\Database\Eloquent\Model; class ProductResource extends Resource{ public static function getGlobalSearchResultUrl(Model $record): string { return self::getUrl('view', ['record' => $record]); }
Notice: global search will not work on "simple" Resources because they don't have Edit/View pages, so there's nowhere to redirect.
For example, our Category/Tag Resources are simple. Their create/edit forms are only in modals, so even if we specify the $recordTitleAttribute
for Categories, they wouldn't appear in the search results.
If you want to search by multiple fields in the same DB table, specify them as an...