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 theapplymethod, to remove the Global Scope added in theindexQuerymethod, and just use whatever the Filter does.
