PHPackages                             marotdc/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. marotdc/laravel-metrics

ActiveLibrary[Admin Panels](/categories/admin)

marotdc/laravel-metrics
=======================

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

2.6.x-dev(2y ago)0234MITPHPPHP ^8.1

Since Oct 11Pushed 2y agoCompare

[ Source](https://github.com/marotdc/laravel-metrics)[ Packagist](https://packagist.org/packages/marotdc/laravel-metrics)[ Docs](https://github.com/marotdc/laravel-metrics)[ RSS](/packages/marotdc-laravel-metrics/feed)WikiDiscussions 2.6 Synced 1mo ago

READMEChangelogDependencies (4)Versions (1)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.

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

[](#installation)

```
composer require marotdc/laravel-metrics
```

Features
--------

[](#features)

- MySQL 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)
```

**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 year 2023
LaravelMetrics::query(Order::query())
    ->count()
    ->byMonth(12)
    ->forYear(2023)
    ->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)
```

**Note :** Make sure to employ the 'fillEmptyDates' method when utilizing the 'between' period to automatically populate any missing dates with a default value. For example:

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

### 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() // or
    ->metrics()
```

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)

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

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 77.8% 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

Unknown

Total

1

Last Release

945d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8986bec95391ed24e6df408e393635a228a5f58c0d054b494cfb7fef506e469d?d=identicon)[marotdc](/maintainers/marotdc)

---

Top Contributors

[![eliseekn](https://avatars.githubusercontent.com/u/49273981?v=4)](https://github.com/eliseekn "eliseekn (42 commits)")[![marotdc](https://avatars.githubusercontent.com/u/139534546?v=4)](https://github.com/marotdc "marotdc (12 commits)")

---

Tags

laravellaravel-packagedashboardcharts

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[eliseekn/laravel-metrics

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

1075.7k](/packages/eliseekn-laravel-metrics)[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)
