PHPackages                             jk-oster/laravel-collection-trend - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jk-oster/laravel-collection-trend

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jk-oster/laravel-collection-trend
=================================

Generate trends from collections. Easily create charts or reports.

v0.1.1(1y ago)013[5 PRs](https://github.com/jk-oster/laravel-collection-trend/pulls)MITPHPPHP ^8CI passing

Since Oct 22Pushed 6mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (14)Versions (8)Used By (0)

Collection Trend for Laravel
============================

[](#collection-trend-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1d0675347789736991cdc97278fc8e38221a4060bfc2d093adf0039b51b64b58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6b2d6f737465722f6c61726176656c2d636f6c6c656374696f6e2d7472656e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jk-oster/laravel-collection-trend)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9edc1b193a026c20234e07120034c449e3a1f7ad30f12f07c087fe9738090d55/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6b2d6f737465722f6c61726176656c2d636f6c6c656374696f6e2d7472656e642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/jk-oster/laravel-collection-trend/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/dd0a54ee4398721dfd396621fa183ff4e67444451b04c5da5c4c5623fae7e4f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6b2d6f737465722f6c61726176656c2d636f6c6c656374696f6e2d7472656e642f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/jk-oster/laravel-collection-trend/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b03857b936361f1d9838a838aa2c62fe5c6d74b7660f2ce66c46d23aa2ad93f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6b2d6f737465722f6c61726176656c2d636f6c6c656374696f6e2d7472656e642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jk-oster/laravel-collection-trend)

Generate trends from collections. Easily create charts or reports.

For detailed examples checkout the [docs page](https://jk-oster.github.io/laravel-collection-trend/).

Why?
----

[](#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](https://github.com/Flowframe/laravel-trend)).

Installation &amp; Setup
------------------------

[](#installation--setup)

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

```
composer require jk-oster/laravel-collection-trend
```

Usage
-----

[](#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

[](#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

[](#interval)

You can use the following aggregates intervals:

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

### Aggregates

[](#aggregates)

You can use the following aggregates:

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

### Date Column

[](#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

[](#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

[](#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
------------------------------------------

[](#compatibility-with-flowframelaravel-trend)

The interface of the package to the biggest part compatible with the [Laravel-Trend](https://github.com/Flowframe/Laravel-Trend) package. You only need to exchange the `Trend::model($model)` calls with `CollectionTrend::make($collectable)`.

License
-------

[](#license)

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

Credits
-------

[](#credits)

Thanks to the creators of [flowframe/laravel-trend](https://github.com/Flowframe/laravel-trend) for inspiration.

- [Jakob Osterberger](https://github.com/jk-oster)
- [All Contributors](../../contributors)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance53

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 67.3% 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

Every ~0 days

Total

2

Last Release

568d ago

PHP version history (2 changes)v0.1.0PHP ^8.2

v0.1.1PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/a7cb92d9b8c8ca66ec52503dc5b91f5d046d2aa2ab3ce03fd8c931e2681b1332?d=identicon)[jk-oster](/maintainers/jk-oster)

---

Top Contributors

[![jk-oster](https://avatars.githubusercontent.com/u/98315600?v=4)](https://github.com/jk-oster "jk-oster (33 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

chartscollectionsdatalaravelphpreportstrendslaraveldatacollectionschartsreportstrendsJakob Osterbergerlaravel-collection-trend

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/jk-oster-laravel-collection-trend/health.svg)

```
[![Health](https://phpackages.com/badges/jk-oster-laravel-collection-trend/health.svg)](https://phpackages.com/packages/jk-oster-laravel-collection-trend)
```

###  Alternatives

[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[nativephp/mobile

NativePHP for Mobile

82724.0k43](/packages/nativephp-mobile)[tonysm/importmap-laravel

Use ESM with importmap to manage modern JavaScript in Laravel without transpiling or bundling.

148399.8k1](/packages/tonysm-importmap-laravel)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[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)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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