### Install Metrics for Laravel with Composer Source: https://github.com/roundly-consulting/metrics-for-laravel/blob/main/README.md Requires PHP 8.4 and Laravel 12 or 13. Run this command to install the package. ```bash composer require roundly-consulting/metrics-for-laravel ``` -------------------------------- ### Read typed metric result in PHP Source: https://github.com/roundly-consulting/metrics-for-laravel/blob/main/README.md Shows how to get a typed result object from a value metric and access its value. The example uses sum on Order total with a ThisMonth range and outputs 15230.0. ```php $revenue = Metrics::value()->sum(Order::query(), 'total')->range(Period::ThisMonth)->result(); $revenue->value(); // 15230.0 ``` -------------------------------- ### Register metrics and return a dashboard Source: https://github.com/roundly-consulting/metrics-for-laravel/blob/main/README.md Shows how to register metrics under keys and return a whole dashboard from one endpoint. The dashboard method returns a Responsable JSON response. ```php Metrics::register('signups', fn () => Metrics::value()->name('Sign-ups')->count(User::query())); Metrics::register('revenue', fn () => Metrics::progress()->name('Revenue')->sum(Order::query(), 'total')->target(10000)); return Metrics::dashboard(['signups', 'revenue'])->range(Period::ThisMonth); // Responsable: JSON ``` -------------------------------- ### Build metrics inline and return JSON Source: https://github.com/roundly-consulting/metrics-for-laravel/blob/main/README.md Shows how to build value, trend, progress, and partition metrics from Eloquent queries. The toArray() method returns a JSON-ready envelope. Includes imports for the Metrics facade and Period enum. ```php use App\Models\Order; use App\Models\User; use RoundlyConsulting\Metrics\Enums\Period; use RoundlyConsulting\Metrics\Facades\Metrics; Metrics::value()->count(User::query()) ->range(Period::Today) ->withChangeAgainstPreviousPeriod() ->toArray(); Metrics::trend()->count(User::query(), 'created_at')->daily()->range(Period::MonthToDate)->toArray(); Metrics::progress()->sum(Order::query(), 'total')->target(10000)->range(Period::MonthToDate)->toArray(); Metrics::partition()->count(User::query(), 'plan')->limit(5)->toArray(); ```