Laravel Trend

flowframe/laravel-trend image

Laravel Trend stats

Downloads
252.2K
Stars
309
Open Issues
7
Forks
42

View on GitHub →

Easily generate model trends

Laravel Trend Package Summary

Overview

The Laravel Trend package provides a fluent, efficient way to generate trends and aggregates such as charts or reports directly from your models in a Laravel application. It simplifies the task of aggregating data over different intervals, making it ideal for applications that require dynamic reporting features.

Key Features

  • Flexible Aggregation: Supports various aggregation operations like sum, average, max, min, and count.
  • Multiple Intervals: Allows data to be aggregated over different time intervals including minute, hour, day, month, and year.
  • Support for Eloquent Queries: Easily integrate with Laravel's Eloquent ORM, supporting both direct model trend analysis or more complex, query-based trends.
  • Database Compatibility: Compatible with MySQL, SQLite, and PostgreSQL, ensuring broad database support.

Installation

Install the package via Composer:

composer require flowframe/laravel-trend

Usage

Begin by importing the Trend class. You can generate trends by starting with either a model or a query, specifying the desired time interval and the type of aggregation.

Examples

  • Total Users per Month:

    $trend = Trend::model(User::class)
    ->between(start: now()->startOfYear(), end: now()->endOfYear())
    ->perMonth()
    ->count();
  • Average Weight of Users Starting with 'A' 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

  • Use ::model() for direct model analysis without additional filters.
  • Use ::query() to incorporate filters and more complex queries.

Aggregation and Intervals

  • Utilize methods like perDay(), perMonth(), etc., to set the aggregation interval.
  • Functions such as sum('column'), average('column'), and others are used to define the type of data aggregation.

Reporting Security Vulnerabilities

For security-related concerns, please refer to the package's security policy documentation.

This package is maintained by Lars Klopstra and other contributors, providing a robust solution for generating data trends in Laravel applications.

Flowframe photo

Flowframe is a web agency specialised in creating delightful web experiences combined with a solid back-end.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Flowframe Laravel Trend Related Articles

5 Underrated Filament Features image

5 Underrated Filament Features

Read article
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian