NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

Metrics::dashboard() resolves a list of registered metrics at once into a single keyed envelope, sharing one range and, optionally, one timezone — ideal for a dashboard endpoint:

use RoundlyConsulting\Metrics\Enums\Period;
use RoundlyConsulting\Metrics\Facades\Metrics;

return Metrics::dashboard(['users', 'revenue', 'churn'])
    ->range(Period::ThisMonth)
    ->timezone('America/New_York')   // optional shared timezone
    ->toArray();
// ['users' => [...envelope...], 'revenue' => [...], 'churn' => [...]]

// A custom window works the same way
Metrics::dashboard(['users', 'revenue'])
    ->range(Period::Custom, '2024-01-01 00:00:00', '2024-03-01 00:00:00')
    ->toArray();
  • range(Period|string $range, ?string $customRangeStart = null, ?string $customRangeEnd = null) — applied to every metric; without it, each metric keeps its own range.
  • timezone(?string $timezone) — resolve every metric in a shared timezone.
  • toArray() — the keyed envelope, one entry per key, in the order given.

Returning a dashboard

Dashboard is Responsable, so a controller returns it directly and gets the JSON envelope:

public function index()
{
    return Metrics::dashboard(['users', 'revenue', 'churn'])->range(request('period', 'TODAY'));
}

Every key must be registered — an unknown key throws UnknownMetricException when the dashboard resolves.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.