beranidigital/laravel-trend
Composer 安装命令:
composer require beranidigital/laravel-trend
包简介
Easily generate model trends. Now with more intervals
README 文档
README
Generate trends for your models. Easily generate charts or reports.
Why?
Most applications require charts or reports to be generated. Doing this over again, and again can be a painful process. That's why we've created a fluent Laravel package to solve this problem.
You can aggregate average, min, max, and totals per minute, hour, day, month, and year.
Installation
You can install the package via composer:
composer require beranidigital/laravel-trend
Usage
To generate a trend for your model, import the Flowframe\Trend\Trend class and pass along a model or query.
Example:
// Totals per month $trend = Trend::model(User::class) ->between( start: now()->startOfYear(), end: now()->endOfYear(), ) ->perMonth() ->count(); // Average user weight where name starts with a over a span of 11 years, results are grouped per year $trend = Trend::query(User::where('name', 'like', 'a%')) ->between( start: now()->startOfYear()->subYears(10), end: now()->endOfYear(), ) ->perYear() ->average('weight');
If you don't specify a date range, the package will automatically determine the range based on the interval you've chosen.
Starting a trend
You must either start a trend using ::model() or ::query(). The difference between the two is that using ::query() allows you to add additional filters, just like you're used to using eloquent. Using ::model() will just consume it as it is.
// Model Trend::model(Order::class) ->between(...) ->perDay() ->count(); // More specific order query Trend::query( Order::query() ->hasBeenPaid() ->hasBeenShipped() ) ->between(...) ->perDay() ->count();
Interval
You can use the following aggregates intervals:
perMinute()perHour()perDay()perWeek()perMonth()perYear()
Aggregates
You can use the following aggregates:
sum('column')average('column')max('column')min('column')count('*')
Date Column
By default, laravel-trend assumes that the model on which the operation is being performed has a created_at date column. If your model uses a different column name for the date or you want to use a different one, you should specify it using the dateColumn(string $column) method.
Example:
Trend::model(Order::class) ->dateColumn('custom_date_column') ->between(...) ->perDay() ->count();
Override Date Format
By default, laravel-trend uses the Y-m-d H:i:s format for the date column. If you want to use a different format, you
should specify it using the Trend::$carbonFormats property.
Example:
Flowframe\Trend\Trend::$carbonFormats['minute'] = 'Y-m-d H:i:00'; Flowframe\Trend\Trend::$carbonFormats['hour'] = 'Y-m-d H:00:00'; Flowframe\Trend\Trend::$carbonFormats['day'] = 'd-M-Y'; Flowframe\Trend\Trend::$carbonFormats['week'] = 'W/Y'; Flowframe\Trend\Trend::$carbonFormats['month'] = 'Y-m'; Flowframe\Trend\Trend::$carbonFormats['year'] = 'Y';
This allows you to work with models that have custom date column names or when you want to analyze data based on a different date column.
Drivers
We currently support three drivers:
- MySQL
- MariaDB
- SQLite
- PostgreSQL
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
beranidigital/laravel-trend 适用场景与选型建议
beranidigital/laravel-trend 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Flowframe」 「laravel-trend」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beranidigital/laravel-trend 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beranidigital/laravel-trend 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beranidigital/laravel-trend 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easily generate model trends
The official Laravel client for PreviewLinks.io
Easily generate model trends
Alfabank REST API integration
Easily generate model trends
Build mail templates for PHP with Brief
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-17