Laravel Community Tools by Tighten
Laravel Nova icon Nova Packages
M

Metric Polling

Installation Instructions

composer require johnpaulmedina/nova-metric-polling

Readme

Latest Version on Packagist Total Downloads

Laravel Nova Metric Polling

An extension of Laravel Nova Metrics to allow for interval polling. Want your Nova dashboard metrics up to date without refreshing, or having to apply a filter? These metrics extend the existing builtin Laravel Nova 4 Metrics and will allow for an interval duration to be set that will trigger an automatic refresh of any number of metrics displayed.

Simple integration to existing Nova\Metrics

Installation

You can install the package in to a Laravel app that uses Nova via composer:

composer require johnpaulmedina/nova-metric-polling

The package will be automatically registered via the MetricPollingServiceProvider

Usage

First, add the following trait use Johnpaulmedina\NoveMetricPolling\ValueInterval to any of your Nova Metrics

<?php

namespace App\Nova\Metrics;

use Johnpaulmedina\NoveMetricPolling\ValueInterval;

Next, let your Metric class inherit the ValueInterval trait through the use keyword like so

<?php

namespace App\Nova\Metrics;

use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Value;
use Laravel\Nova\Nova;
use Johnpaulmedina\NovaMetricPolling\ValueInterval;

class ActiveUsers extends Value
{
    use ValueInterval;

Finally, instantiate your Metric and call the refreshAtInterval(Int: n) method. The method accepts an integer value which will be calculated in seconds.

    /**
     * Get the cards available for the request.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function cards(NovaRequest $request)
    {
        return [
            (new Metrics\ActiveUsers())->refreshAtInterval(300), // (IE: 300 seconds / 60 = 5 minutes)
        ];
    }

Alternatively, you may also set and integer value on the public property $refreshAtInterval.

<?php

namespace App\Nova\Metrics;

use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Value;
use Laravel\Nova\Nova;
use Johnpaulmedina\NovaMetricPolling\ValueInterval;

class ActiveUsers extends Value
{
    use ValueInterval;

    public $refreshAtInterval = 300; // (IE: 300 seconds / 60 = 5 minutes)

License

The MIT License (MIT). Please see License File for more information.

Reviews

By msang47 on July 21, 2023

Very useful! Props to the author!

Back to Top
Added 2 years ago
Last updated 2 Years Ago
Version v1.0.2
Nova Version ^4.0
Composer
johnpaulmedina/nova-metric-polling
GitHub stars 7
Packagist downloads 14,381

Favorites

2 users favorited

Rating

5.00
(out of 5)
★★★★★
★★★★
★★★
★★
2 ratings

Brought to you by Tighten

Issues/Feature Requests Stats Package Ideas