---
title: "The Metrics facade — Metrics for Laravel | Roundly"
description: "The whole API on one facade — inline builders, the metric registry, dashboards, cache invalidation and the recording fake."
url: https://roundly-consulting.com/open-source/docs/metrics-for-laravel/facade
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Metrics for Laravel](https://roundly-consulting.com/open-source/docs/metrics-for-laravel.md)

# The Metrics facade

RoundlyConsulting\\Metrics\\Facades\\Metrics is the recommended entry point. Its root is RoundlyConsulting\\Metrics\\MetricsManager, a container singleton (also bound as metrics) that registers, resolves and invalidates metrics. The whole surface at a glance:

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

// Build inline — one builder per metric type
Metrics::value()->count(User::query())->range(Period::Today)->result();
Metrics::trend()->count(User::query(), 'created_at')->daily()->toArray();
Metrics::progress()->sum(Order::query(), 'total')->target(10000)->toArray();
Metrics::partition()->count(User::query(), 'plan')->toArray();

// Registry
Metrics::register('revenue', MonthlyRevenueGoal::class);
Metrics::get('revenue')->range('MTD')->toArray();
Metrics::has('revenue'); Metrics::keys(); Metrics::all();

// Many at once, and cache invalidation
Metrics::dashboard(['users', 'revenue'])->range(Period::ThisMonth)->toArray();
Metrics::forget('revenue');
Metrics::flushCache();

Metrics::unregister('revenue');
```

## Every method

| Method | Returns | Purpose |
| --- | --- | --- |
| `value() / trend() / progress() / partition()` | a pending builder | Build a metric inline. |
| `register(string $key, string\|Metric\|Closure $metric)` | `MetricsManager` | Add a metric to the registry (chainable). |
| `unregister(string $key)` | `MetricsManager` | Remove it (chainable). |
| `get(string $key)` | `Metric` | Resolve one (a fresh copy), tagged with its key. |
| `has(string $key) / keys() / all()` | `bool / list<string> / array<string, Metric>` | Inspect the registry. |
| `dashboard(array $keys)` | `Dashboard` | Resolve many at once. |
| `forget(string\|Metric $metric)` | `void` | Forget one metric’s cached results. |
| `flushCache()` | `void` | Forget every cached result. |
| `fake(array $results = [])` | `MetricsFake` | Swap in the recording fake (see Testing). |

- The builders return a pending metric — PendingValue, PendingTrend, PendingProgress or PendingPartition — with the same fluent API as a metric class; see Aggregate helpers and Metric classes.
- get() throws UnknownMetricException for an unregistered key; so does forget() — see Registry and Caching.
- The facade alias is Metrics; the abstract base class every metric extends is RoundlyConsulting\\Metrics\\Metric.

## 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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/metrics-for-laravel.md)
