Easily add polling to all your Laravel Nova metrics and cards!
fidum/laravel-nova-metrics-polling is a Laravel package for easily add polling to all your laravel nova metrics and cards!.
It currently has 6 GitHub stars and 13.801 downloads on Packagist (latest version 1.0.4).
Install it with composer require fidum/laravel-nova-metrics-polling.
Discover more Laravel packages by fidum
or browse all Laravel packages to compare alternatives.
Last updated
Easily add polling to all your Laravel Nova metrics and cards!
You can install the package via composer:
composer require fidum/laravel-nova-metrics-polling
Firstly, just add the SupportsPolling trait to any of your Metrics or Card classes:
<?php
namespace App\Nova\Metrics;
use Fidum\LaravelNovaMetricsPolling\Concerns\SupportsPolling;
class NewUsers extends Value
{
use SupportsPolling;
Then in the Dashboard, Resource or Lens cards method where you have registered your card you can call refreshIntervalSeconds and pass in the number of seconds you want the interval to be between refresh requests. You can
also pass a closure as needed.
use App\Nova\Metrics\NewUsers;
use App\Nova\Metrics\NewOrders;
public function cards(NovaRequest $request)
{
return [
NewUsers::make()->refreshIntervalSeconds(30),
NewOrders::make()->refreshIntervalSeconds(fn () => 30),
];
}
If preferred, you can call refreshIntervalMilliseconds instead and pass in the number of milliseconds you want the interval to be between refresh requests.
use App\Nova\Metrics\NewUsers;
use App\Nova\Metrics\NewOrders;
public function cards(NovaRequest $request)
{
return [
NewUsers::make()->refreshIntervalMilliseconds(30000),
NewOrders::make()->refreshIntervalMilliseconds(fn () => 30000),
];
}
That is it, your cards should now be polling at the specified intervals! :tada:
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.