There is currently no way to use a Filter for a Resource in the default view. However, for the desired outcome, it’s possible to use a combination of the Nova indexQuery method and Laravels global scopes.
- Create a scope with the desired default filter:
php artisan make:scope DefaultFilterScope
- Use this scope in the indexQuery method of the Nova Resource like so:
public static function indexQuery(NovaRequest $request, $query) { return $query->withGlobalScope(DefaultFilterScope::class, new DefaultFilterScope); }
- In the other Filters for this Resource, add
$query = $query->withoutGlobalScope(DefaultFilterScope::class);
in the first line of theapply
method, to remove the Global Scope added in theindexQuery
method, and just use whatever the Filter does.