jk-oster/laravel-collection-trend 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jk-oster/laravel-collection-trend

Composer 安装命令:

composer require jk-oster/laravel-collection-trend

包简介

Generate trends from collections. Easily create charts or reports.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Generate trends from collections. Easily create charts or reports.

For detailed examples checkout the docs page.

Why?

Most applications require charts or reports to be generated. Doing this over again, and again can be a painful process. That's why I've created a fluent Laravel package to solve this problem (inspired by laravel-trend).

Installation & Setup

You can install this package with composer using the following command:

composer require jk-oster/laravel-collection-trend

Usage

To generate a trend for your model, import the JkOster\CollectionTrend\CollectionTrend class and pass along a collectable.

Example:

// Totals per month
$trend = CollectionTrend::make($collectable)
    ->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 = CollectionTrend::make($collectable)
    ->between(
        start: now()->startOfYear()->subYears(10),
        end: now()->endOfYear(),
    )
    ->perYear()
    ->average('weight');

Starting a trend

You can either start a trend using ::make() or ::collect().

CollectionTrend::make($collectable)
    ->between(...)
    ->perDay()
    ->count();

CollectionTrend::collect($collectable)
    ->between(...)
    ->perDay()
    ->count();

Interval

You can use the following aggregates intervals:

perMinute()
perHour()
perDay()
perMonth()
perYear()

Aggregates

You can use the following aggregates:

sum('column')
average('column')
median('column')
max('column')
min('column')
count('*')

Date Column

By default, laravel-collection-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|Closure $column) method.

Example:

CollectionTrend::make($collectable)
    ->dateColumn('custom_date_column')
    ->between(...)
    ->perDay()
    ->count();

// Or using a closure

CollectionTrend::collect($collectable)
    ->dateColumn(fn ($item) => $item['custom_date_column'])
    ->between(...)
    ->perDay()
    ->count();

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.

Value Column

By default laravel-collection-trend you have to specify the column that contains the values you want to aggregate in the aggregate method. Like the date column you can specify it using a string|Closure which you pass in the aggregate method.

Example:

CollectionTrend::make($collectable)
    ->between(...)
    ->perDay()
    ->sum('value_column');

// Or using a closure

CollectionTrend::collect($collectable)
    ->between(...)
    ->perDay()
    ->sum(fn ($item) => $item['value_column']);

Empty Data Fillers

By default laravel-collection-trend fills up missing data with the value 0. You can change this behavior by passing a int as second argument to the aggregate method.

Example:

CollectionTrend::make($collectable)
    ->between(...)
    ->perDay()
    ->sum('value_column', -1);

Compatibility with Flowframe/Laravel-Trend

The interface of the package to the biggest part compatible with the Laravel-Trend package. You only need to exchange the Trend::model($model) calls with CollectionTrend::make($collectable).

License

The MIT License (MIT). Please see License File for more information.

Credits

Thanks to the creators of flowframe/laravel-trend for inspiration.

jk-oster/laravel-collection-trend 适用场景与选型建议

jk-oster/laravel-collection-trend 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「collections」 「data」 「charts」 「laravel」 「reports」 「trends」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jk-oster/laravel-collection-trend 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jk-oster/laravel-collection-trend 我们能提供哪些服务?
定制开发 / 二次开发

基于 jk-oster/laravel-collection-trend 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-16