emilhorlyck/laravel-poly-metrics
最新稳定版本:0.1.0
Composer 安装命令:
composer require emilhorlyck/laravel-poly-metrics
包简介
This is my package laravel-poly-metrics
README 文档
README
This package allows you to log metrics for multiple models, and even without relation to a models in laravel.
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
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
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
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
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-16