1. Go to this page and download the library: Download syriable/laravel-metrics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
syriable / laravel-metrics example snippets
use Syriable\Metrics\Facades\Metrics;
// One number, compared against the previous 30 days — in a single query.
$result = Metrics::query(Order::class)
->sum('total')
->range('30d')
->compareWithPrevious()
->value();
$result->value(); // 48250.75
$result->comparison()->percentage; // 12.4
$result->comparison()->direction; // Direction::Up
$result->toArray(); // normalized API payload
// A gap-filled daily series.
$trend = Metrics::query(Order::class)
->count()
->range('mtd')
->perDay()
->trend();
// A group-by breakdown with engine-computed percentages.
$partition = Metrics::query(Order::class)
->count()
->groupBy('status')
->top(5) // fold the tail into "others"
->partition();
->range('qtd') // named
->range('12mo') // rolling
->between('2026-01-01', '2026-06-30') // explicit period
->allTime() // unbounded
->compareWithPrevious() // immediately preceding period
->compareWithPreviousWeek() // same window, shifted back
->compareWithPreviousMonth() // (no month-overflow surprises)
->compareWithPreviousQuarter()
->compareWithPreviousYear()
->compareWith($customStrategy) // your own ComparisonStrategy
class OrdersRevenue extends Metric
{
public function query(): MetricBuilder
{
return Metrics::query(Order::class)
->sum('total')->range('30d')->compareWithPrevious()->cache(300);
}
}
// e.g. in a controller:
Route::get('/api/metrics/{key}', function (string $key, Request $request) {
return Metrics::run($key, $request->only(['range', 'interval', 'timezone', 'compare']));
});