MIT License

项目介绍

Flowframe/laravel-trend 是一个托管在 GitHub 上的开源项目,主要使用 PHP 编写,采用 MIT License 许可证,目前获得 1.1k 个 Star、97 次 Fork。

仓库全名
Flowframe/laravel-trend
开源许可证
MIT License
Star 数
1.1k
Fork 数
97
未关闭 Issue
21

README 摘要

Laravel Trend 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…

完整内容见 GitHub 原始 README 或本页 。

常见问题

laravel-trend 用什么语言开发?

主要使用 PHP 编写,采用 MIT License 许可证,目前有 1.1k 个 Star。

laravel-trend 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 laravel-trend 的源码?

可以直接克隆仓库:git clone https://github.com/Flowframe/laravel-trend.git,默认分支为 master;安装与运行步骤见仓库 README。

laravel-trend 最近还在维护吗?

仓库最近一次更新为 3月30日,当前有 21 个未关闭 Issue;Star 数为 1.1k,可作为社区活跃度的参考。

简要分析

热度分
1324
价值分
702
活跃状态
活跃

语言占比

PHP

Release

README

Laravel Trend

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 flowframe/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');

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()
  • 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();

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 four 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.

评论

暂无评论