This package allows you to broadcast any of your existing Laravel Nova filters to metrics or custom cards.
one-strive/nova-global-filter is a Laravel package for this package allows you to broadcast any of your existing laravel nova filters to metrics or custom cards..
It currently has 1 GitHub stars and 4.602 downloads on Packagist (latest version 5.3).
Install it with composer require one-strive/nova-global-filter.
Discover more Laravel packages by one-strive
or browse all Laravel packages to compare alternatives.
Last updated
This package allows you to emit any of your existing Laravel Nova filters to metrics or custom cards.
Note: This is a community-maintained fork of the original package. We've taken over maintenance of this abandoned package to ensure continued support for the Laravel Nova community. This version is compatible with Nova 5 only.

You can install the package in to a Laravel app that uses Nova via composer:
composer require OneStrive/nova-global-filter
In this example, we are registering few Metric Cards and the Global Filter with a Date filter as:
...
use OneStrive\NovaGlobalFilter\NovaGlobalFilter;
use App\Nova\Filters\Date;
class Store extends Resource
{
...
public function cards(Request $request)
{
return [
new TotalSales // Value Metric
new Orders, // Trend Metric
new MostSoldProduct, // Partition Metric
// NovaGlobalFilter
NovaGlobalFilter::make()->filters([
new Date, // Date Filter
]),
];
}
...
}
And now metric cards or any other cards optimized to listen GlobalFilter can be filtered by using GlobalFilterable trait and calling $this->globalFiltered($model,$filters) method.
globalFiltered($model, $filters = []) method expect $model and $filters parameters:
use OneStrive\NovaGlobalFilter\GlobalFilterable;
use App\Nova\Filters\Date;
...
class UsersPerDay extends Trend
{
use GlobalFilterable;
public function calculate(NovaRequest $request)
{
// Filter your model with existing filters
$model = $this->globalFiltered($request, Store::class,[
Date::class // DateFilter
]);
// Do your thing with the filtered $model
return $this->countByDays($request, $model);
}
...
}
And that's it. Cards will be filtered based on passed filter value.
If you want to apply default value on initial request make sure you set default value in your filter as
...
// set default date
public function default()
{
return Carbon::now();
}
...
To change layout from grid to inline
by default it's set to grid
...
NovaGlobalFilter::make()
->filters([
// Filters
]),
...
To enable Reset button
...
NovaGlobalFilter::make()
->filters([
// Filters
])
->resettable(),
...
To add multiple Global Filters
...
NovaGlobalFilter::make()
->filters([
// Filters
])
->inline()
->resettable(),
NovaGlobalFilter::make()
->filters([
// Filters
])
->onlyOnDetail(),
...
To set Title of Global Filter
...
NovaGlobalFilter::make()
->filters([
// Filters
])
->title('Example Title'),
...
To listen Global Filter on any Custom Cards:
...
created() {
Nova.$on("global-filter-changed", filter => {
// Do your thing with the changed filter
console.log(filter);
});
},
...
To request all filter states from Global Filter on any Custom Cards:
...
Nova.$emit("global-filter-request");
...
To request spesific filters state from Global Filter on any Custom Cards:
...
created() {
Nova.$emit("global-filter-request", [
"App\\Nova\\Filters\\DateFilter",
"App\\Nova\\Filters\\CountryFilter"
]);
},
...
To receive filters state from Global Filter on any Custom Cards:
...
created() {
Nova.$on("global-filter-response", filters => {
// Do your thing with the filters
console.log(filters);
});
},
...
Nova.$on('global-filter-changed', [changed filter and value]). So any card that listens to this event will recieve the filter and its value.Metric Cards to allow them to listen "global-filter-changed" event. Make sure there are no any conflicts with other pacages.Global Filter will not trigger update at the filters in Filter Menu of your Index view.Reset button simply reloads the current page. There is nothing fancy going on behind the scenes.Star the package.This package is a maintained fork of the original work by:
We're grateful for their excellent foundational work and are committed to keeping this valuable tool available for the Nova community.
Current maintainers:
Made with ❤️ for open source
The MIT License (MIT). Please see License File for more information.