-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5858e60
commit 921292b
Showing
6 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
build | ||
composer.lock | ||
coverage | ||
docs | ||
phpunit.xml | ||
psalm.xml | ||
testbench.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
url: https://github.com/flowframe/laravel-trend | ||
name: laravel-trend | ||
fullName: flowframe/laravel-trend | ||
description: Generate trends for your models. Easily generate charts or reports. | ||
language: PHP | ||
license: MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
category: Getting started | ||
title: Drivers | ||
order: 4 | ||
--- | ||
|
||
We currently support two drivers: | ||
|
||
- MySQL | ||
- Sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
category: Getting started | ||
title: About | ||
order: 1 | ||
--- | ||
|
||
This packages allows you to easily generate trends for your models. | ||
|
||
## Why? | ||
|
||
Most applications require charts or reports to be generated. Doing this over again, and again can be a painfull 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
category: Getting started | ||
title: Installation and setup | ||
order: 3 | ||
--- | ||
|
||
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: | ||
|
||
```php | ||
// 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. | ||
|
||
```php | ||
// 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('*')` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
category: Getting started | ||
title: Requirements | ||
order: 2 | ||
--- | ||
|
||
This package requires: | ||
|
||
- PHP 8 or higher |