Blog Detail


Generate Trends, Charts, or Reports for Models in Laravel cover image

arrow_back Generate Trends, Charts, or Reports for Models in Laravel

Most applications require charts or reports to be generated. Doing this over again, and again can be a painful process. That’s why Flowframe has created a fluent Laravel package called Laravel Trend to solve this problem. You can aggregate average, min, max, and totals per minute, hour, day, month, and year. Laravel Trend packages allow you to easily generate trends for your models.

This package requires PHP 8 or higher.

Installation and setup

You can install the package via composer:

composer require flowframe/laravel-trend


To generate a trend for your model, import the Flowframe\Trend\Trend class and pass along a model or query.


// Totals per month
$trend = Trend::model(User::class)
        start: now()->startOfYear(),
        end: now()->endOfYear(),

// 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%'))
        start: now()->startOfYear()->subYears(10),
        end: now()->endOfYear(),

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

// More specific order query


You can use the following aggregates intervals:

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


You can use the following aggregates:

  • sum(‘column’)
  • average(‘column’)
  • max(‘column’)
  • min(‘column’)
  • count(’*’)


We currently support three drivers:

  • MySQL
  • SQLite
  • PostgreSQL
  • Edit on GitHub

For more details, Visit Github

Closing Note

If you are looking for a custom CRM system or eCommerce web application for your enterprise, then we are here to help you. The Web development team at Codebrisk has notable experience in the Laravel e-commerce and CRM web development field. We can provide you with custom-made e-commerce web applications with a lot of cutting-edge features and options. We will be pleased to assist you with your projects. Please feel free to contact us or you can launch a project with us.

Published at : 04-07-2022

Author : Rizwan Aslam
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project