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

ActiveLibrary

emilhorlyck/laravel-poly-metrics
================================

This is my package laravel-poly-metrics

0.1.0(1y ago)035[4 PRs](https://github.com/emilhorlyck/laravel-poly-metrics/pulls)MITPHPPHP ^8.2CI passing

Since Oct 18Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/emilhorlyck/laravel-poly-metrics)[ Packagist](https://packagist.org/packages/emilhorlyck/laravel-poly-metrics)[ Docs](https://github.com/emilhorlyck/laravel-poly-metrics)[ GitHub Sponsors](https://github.com/emilhorlyck)[ RSS](/packages/emilhorlyck-laravel-poly-metrics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (12)Versions (6)Used By (0)

This is `laravel-poly-metrics` to log metrics for multiple models
=================================================================

[](#this-is-laravel-poly-metrics-to-log-metrics-for-multiple-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4688c5e325818f7b62e2e33c2ceb008cd68424c36c09c84390101358d73c734e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656d696c686f726c79636b2f6c61726176656c2d706f6c792d6d6574726963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/emilhorlyck/laravel-poly-metrics)[![GitHub Tests Action Status](https://camo.githubusercontent.com/dc536cb9ae9e38625b5b0619322b0a85eb930450f41f532dda8df50bafc84edf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656d696c686f726c79636b2f6c61726176656c2d706f6c792d6d6574726963732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/emilhorlyck/laravel-poly-metrics/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/5adbc1f4463856cbf7330c90029ee684f88dc8f924c15aafbf9a62dff9af49fe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f656d696c686f726c79636b2f6c61726176656c2d706f6c792d6d6574726963732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/emilhorlyck/laravel-poly-metrics/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/6a5915b870d8e81e8ed63f95b837ee36098a49de3900afe971d0096d87464e33/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656d696c686f726c79636b2f6c61726176656c2d706f6c792d6d6574726963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/emilhorlyck/laravel-poly-metrics)

This package allows you to log metrics for multiple models, and even without relation to a models in laravel.

Features
--------

[](#features)

- Log metrics without relation to a model
    - Daily resolution
    - Monthly resolution
- Log metrics with relation to a model
    - Daily resolution
    - Monthly resolution
- Offer traits to easily log metrics on models
- Offer command to purge old metrics
- Offer command to purge old metrics for a specific model
- Deafult scheduled command to purge old metrics

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

[](#installation)

You can install the package via composer:

```
composer require emilhorlyck/laravel-poly-metrics
```

You can publish all the necessary files with:

```
php artisan vendor:publish --provider="EmilHorlyck\PolyMetric\PolyMetricServiceProvider"
```

You can them run the migrations with:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Log metrics without relation to a model

[](#log-metrics-without-relation-to-a-model)

```
// Modify metrics with daily and monthly resolution
PolyMetric::set('my-metric', 42); // This will set the metric to 42
PolyMetric::increment('my-metric'); // This will increment the metric by 1
PolyMetric::decrement('my-metric'); // This will decrement the metric by 1

// Modify metrics with only daily resolution
PolyMetric::setDaily('my-metric', 42); // This will set the metric to 42
PolyMetric::incrementDaily('my-metric'); // This will increment the metric by 1
PolyMetric::decrementDaily('my-metric'); // This will decrement the metric by 1

// Modify metrics with only monthly resolution
PolyMetric::setMonthly('my-metric', 42); // This will set the metric to 42
PolyMetric::incrementMonthly('my-metric'); // This will increment the metric by 1
PolyMetric::decrementMonthly('my-metric'); // This will decrement the metric by 1
```

### Log metrics with relation to a model

[](#log-metrics-with-relation-to-a-model)

Add the `HasMetrics` trait to your model.

```
use EmilHorlyck\PolyMetric\Traits\HasMetrics;

class User extends Model
{
    use HasMetrics;
}
```

Log metrics on the model

```
$user = User::find(1);

// Modify metrics with daily and monthly resolution
$user->setMetric('my-metric', 42); // This will set the metric to 42
$user->incrementMetric('my-metric'); // This will increment the metric by 1
$user->decrementMetric('my-metric'); // This will decrement the metric by 1

// Modify metrics with only daily resolution
$user->setDailyMetric('my-metric', 42); // This will set the metric to 42
$user->incrementDailyMetric('my-metric'); // This will increment the metric by 1
$user->decrementDailyMetric('my-metric'); // This will decrement the metric by 1

// Modify metrics with only monthly resolution
$user->setMonthlyMetric('my-metric', 42); // This will set the metric to 42
$user->incrementMonthlyMetric('my-metric'); // This will increment the metric by 1
$user->decrementMonthlyMetric('my-metric'); // This will decrement the metric by 1
```

Credits
-------

[](#credits)

- [Emil Hørlyck](https://github.com/emilhorlyck)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance67

Regular maintenance activity

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.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

571d ago

### Community

Maintainers

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

---

Top Contributors

[![emilhorlyck](https://avatars.githubusercontent.com/u/25416509?v=4)](https://github.com/emilhorlyck "emilhorlyck (56 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")

---

Tags

laravelemilHorlycklaravel-poly-metrics

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2651.3M6](/packages/spatie-laravel-prometheus)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[scalar/laravel

Render your OpenAPI-based API reference

6183.9k2](/packages/scalar-laravel)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)[musahmusah/laravel-multipayment-gateways

A Laravel Package that makes implementation of multiple payment Gateways endpoints and webhooks seamless

852.2k1](/packages/musahmusah-laravel-multipayment-gateways)

PHPackages © 2026

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