PHPackages                             eliseekn/laravel-metrics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. eliseekn/laravel-metrics

ActiveLibrary[Admin Panels](/categories/admin)

eliseekn/laravel-metrics
========================

Generate easily metrics and trends data of your models for your dashboards.

v3.1.1(1y ago)1075.7k↑62.5%8MITPHPPHP ^8.2

Since Sep 25Pushed 1y ago2 watchersCompare

[ Source](https://github.com/eliseekn/laravel-metrics)[ Packagist](https://packagist.org/packages/eliseekn/laravel-metrics)[ Docs](https://github.com/eliseekn/laravel-metrics)[ Fund](https://www.buymeacoffee.com/eliseekn)[ GitHub Sponsors](https://github.com/eliseekn)[ RSS](/packages/eliseekn-laravel-metrics/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (77)Used By (0)

Metrics for Laravel
===================

[](#metrics-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8580217c17079c9c36030cd99ac67f2bbe5a2fc39814b9634c5fb6d317f64536/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c697365656b6e2f6c61726176656c2d6d6574726963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eliseekn/laravel-metrics)[![Total Downloads](https://camo.githubusercontent.com/affc9ffff9cc89da2f50376366a9dbc2bf3899e9c3d82aed66db880d4ed56012/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c697365656b6e2f6c61726176656c2d6d6574726963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eliseekn/laravel-metrics)

Generate easily metrics and trends data of your models for your dashboards.

Requirements
------------

[](#requirements)

```
PHP ^8.1.x
Laravel ^10.x
```

***Note :*** For Laravel 11.x support check [3.x](https://github.com/eliseekn/laravel-metrics/tree/3.x) branch.

Installation
------------

[](#installation)

```
composer require eliseekn/laravel-metrics
```

Features
--------

[](#features)

- MySQ, PostgreSQL and SQLite support
- Verbose query builder
- Custom columns and table definition
- Days and months translation with Carbon

Usage
-----

[](#usage)

### With Eloquent Query

[](#with-eloquent-query)

Import the `Eliseekn\LaravelMetrics\LaravelMetrics` class in your controller and use it as follows :

- Basic usage

```
// generate trends of products amount's sum for the current year
LaravelMetrics::query(Product::query())
    ->count()
    ->byMonth()
    ->trends();

// generate trends of orders amount's sum for the last 6 months of the current year including current month
LaravelMetrics::query(Order::query())
    ->sum('amount')
    ->byMonth(6)
    ->trends();

// generate total orders amount's sum
LaravelMetrics::query(Order::query())
    ->sum('amount')
    ->byYear()
    ->metrics();

// generate total product count for the current day
LaravelMetrics::query(Product::query())
    ->count()
    ->byDay(1)
    ->metrics();
```

- Using custom query

```
LaravelMetrics::query(
    Post::query()->where('user_id', auth()->id())
)
    ->count()
    ->byDay()
    ->trends();
```

- Using custom date column

```
LaravelMetrics::query(Post::query())
    ->count()
    ->byDay()
    ->dateColumn('published_at')
    ->trends();
```

- Using date range

```
LaravelMetrics::query(Post::query()))
    ->count()
    ->between('2020-05-01', '2022-08-21')
    ->trends();
```

- Using custom label column

```
LaravelMetrics::query(Order::query())
    ->count()
    ->byMonth(12)
    ->labelColumn('status')
    ->trends();
```

- Using custom table

```
LaravelMetrics::query(
    Order::query()->join('users', 'orders.id', 'users.order_id')
)
    ->count()
    ->table('users')
    ->labelColumn('name')
    ->trends();
```

### With Query Builder

[](#with-query-builder)

```
LaravelMetrics::query(
    DB::table('orders')
)
    ->sum('amount')
    ->byMonth()
    ->trends();
```

### With traits

[](#with-traits)

Add `HasMetrics` trait to your models and use it as follows :

```
Order::metrics()
    ->sum('amount')
    ->byMonth()
    ->trends();
```

### Types of periods

[](#types-of-periods)

```
LaravelMetrics::query(...)
    ->byDay(int $count = 0) //or
    ->byWeek(int $count = 0) //or
    ->byMonth(int $count = 0) //or
    ->byYear(int $count = 0) //or
    ->between(string $startDate, string $endDate, string $dateIsoFormat) //or
    ->from(string $date, string $dateIsoFormat)
```

***Note :*** Periods are defined for the current day, week, month or year by default. However, you can define a specific value using dedicated methods. For example:

```
// generate trends of orders count for the current year
LaravelMetrics::query(Order::query())
    ->count()
    ->byMonth(12)
    ->forYear(now()->year)
    ->labelColumn('status')
    ->trends();

// generate total orders amount's sum for the third month only
LaravelMetrics::query(Product::query())
    ->sum('amount')
    ->byMonth(1)
    ->forMonth(3)
    ->metrics();
```

```
LaravelMetrics::query(...)
    ->forDay(int $day)
    ->forWeek(int $week)
    ->forMonth(int $month)
    ->forYear(int $year)
```

### Types of aggregates

[](#types-of-aggregates)

```
LaravelMetrics::query(...)
    ->count(string $column = 'id') //or
    ->average(string $column) //or
    ->sum(string $column) //or
    ->max(string $column) //or
    ->min(string $column)
```

### Types of data

[](#types-of-data)

```
LaravelMetrics::query(...)
    ->trends(bool $inPercent = false) //or
    ->metrics() //or
    ->metricsWithVariations(int $previousCount, string $previousPeriod, bool $inPercent = false)
```

***Note 1 :*** The `trends` method can generate data in percentage format when the `$inPercent` parameter is set to `true`.

***Note 2 :*** The `metricsWithVariations` method generates metrics with variations from the `$previousPeriod` period (`day`, `week`, `month`, or `year`). The `$previousCount` parameter specifies the count for the past period. Set `$inPercent` parameter to true to get variations result in percent.

### Combining periods and aggregates

[](#combining-periods-and-aggregates)

Combining different time periods and data aggregates can enhance your overall experience. For example :

```
LaravelMetrics::query(...)
    ->sumByYear()
    ->trends();

LaravelMetrics::query(...)
    ->countByMonth(count: 12)
    ->forYear(now()->year)
    ->labelColumn('status')
    ->trends();

LaravelMetrics::query(...)
    ->countBetween([Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d')])
    ->trends();

LaravelMetrics::query(...)
    ->averageFrom(Carbon::now()->subDays(10)->format('Y-m-d'))
    ->trends();
...
```

Possible combinations :

```
LaravelMetrics::query(...)
    ->countByMonth(...) //or
    ->countByYear(...) //or
    ->countByDay(...) //or
    ->countByWeek(...) //or
    ->sumByMonth(...) //or
    ->sumByYear(...) //or
    ->sumByDay(...) //or
    ->sumByWeek(...) //or
    ->averageByMonth(...) //or
    ->averageByYear(...) //or
    ->averageByDay(...) //or
    ->averageByWeek(...) //or
    ->maxByMonth(...) //or
    ->maxByYear(...) //or
    ->maxByDay(...) //or
    ->maxByWeek(...) //or
    ->minByMonth(...) //or
    ->minByYear(...) //or
    ->minByDay(...) //or
    ->minByWeek(...) //or
    ->countBetween(...) //or
    ->sumBetween(...) //or
    ->averageBetween(...) //or
    ->maxBetween(...) //or
    ->minBetween(...) //or
    ->countFrom(...) //or
    ->sumFrom(...) //or
    ->averageFrom(...) //or
    ->maxFrom(...) //or
    ->minFrom(...)
```

### Fill missing data with default value

[](#fill-missing-data-with-default-value)

You can fill missing data with default value with the global method `fillMissingData`, especially for trends. For example :

```
LaravelMetrics::query(...)
    ->countBetween([Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d')])
    ->fillMissingData()
    ->trends();

LaravelMetrics::query(...)
    ->sumByYear(count: 5)
    ->fillMissingData()
    ->trends();
...
```

***Note :*** The `fillMissingData` method automatically discovers all labels, ensuring that data is filled for all available labels without the need for explicit label specification.

### Group period (only when using `between` method)

[](#group-period-only-when-using-between-method)

You can group period by days, months, weeks or years when using the `between` method (***default is day***). For example :

```
LaravelMetrics::query(...)
    ->countBetween([Carbon::now()->subDays(10)->format('Y-m-d'), Carbon::now()->format('Y-m-d')])
    ->groupByMonth()
    ->fillMissingData()
    ->trends();
```

```
LaravelMetrics::query(...)
    ->groupByYear() //or
    ->groupByMonth() //or
    ->groupByWeek() //or
    ->groupByDay()
```

### Group data (only for `trends`)

[](#group-data-only-for-trends)

You can group data of a column with multiple values to use it in a dataset for your charts. For example :

```
Order::metrics()
    ->countByMonth(column: 'status')
    ->groupData(['pending', 'delivered', 'cancelled'], Aggregate::SUM->value)
    ->fillMissingData()
    ->trends();
```

***Note :*** Follow same order in the example to avoid false data.

Translations
------------

[](#translations)

Days and months names are automatically translated using `config(app.locale)` except 'week' period.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email `eliseekn@gmail.com` instead of using the issue tracker.

Credits
-------

[](#credits)

- [N'Guessan Kouadio Elisée](https://github.com/eliseekn)
- [Chris Brown](https://github.com/drbyte)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Demo
----

[](#demo)

You can find a demo project [here](https://github.com/eliseekn/laravel-metrics-demo).

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance43

Moderate activity, may be stable

Popularity38

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 98.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~62 days

Total

73

Last Release

448d ago

Major Versions

v2.9.3 → v3.0.1-beta-12024-04-21

v2.9.4 → v3.0.32024-04-24

v2.9.5 → v3.0.42024-05-06

v2.10.0 → v3.1.02024-06-22

2.x-dev → 3.x-dev2025-02-25

PHP version history (4 changes)v1.0.0PHP ^7.4|^8.0

1.0.7.x-devPHP ^8.0

v2.0.0PHP ^8.1

v3.0.0-beta-1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5582d4e113993fd09845f4313656dcb72b7d70663d0a2ab76edfec9674fe0ef?d=identicon)[eliseekn](/maintainers/eliseekn)

---

Top Contributors

[![eliseekn](https://avatars.githubusercontent.com/u/49273981?v=4)](https://github.com/eliseekn "eliseekn (70 commits)")[![drbyte](https://avatars.githubusercontent.com/u/404472?v=4)](https://github.com/drbyte "drbyte (1 commits)")

---

Tags

chartsdashboardlaravellaravel-packagephptrendlaravellaravel-packagedashboardcharts

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/eliseekn-laravel-metrics/health.svg)

```
[![Health](https://phpackages.com/badges/eliseekn-laravel-metrics/health.svg)](https://phpackages.com/packages/eliseekn-laravel-metrics)
```

###  Alternatives

[sebastienheyd/boilerplate

Laravel Boilerplate based on AdminLTE 3 with blade components, user management, roles, permissions, logs viewer, ...

28618.2k3](/packages/sebastienheyd-boilerplate)[takielias/tablar-kit

The Elegance of Tablar Dashboard

413.4k](/packages/takielias-tablar-kit)[takielias/tablar-crud-generator

Laravel Tablar Crud Generator based on https://github.com/takielias/tablar

315.6k](/packages/takielias-tablar-crud-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
