Git Product home page Git Product logo

laravel-trend's Introduction

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 three drivers:

  • MySQL
  • 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.

laravel-trend's People

Contributors

larsklopstra avatar devatreides avatar laravel-shift avatar mwikala avatar pktharindu avatar raymon-roos avatar wit3 avatar ymigval avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.