zaimealabs / aggregate
The ZaimeaLabs Aggregate package.
Fund package maintenance!
Custura
Requires
- php: ^8.2
- illuminate/contracts: ^10.0|^11.0
Requires (Dev)
- nunomaduro/collision: ^7.0|^8.0
- orchestra/testbench: ^8.0|^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- vimeo/psalm: ^5.0
README
Generate aggregate for your models to generate charts or reports in your application.
Hey 👋 thanks for considering making a donation, with these donations I can continue working to contribute to ZaimeaLabs projects.
Usage
To generate a aggregate for your model, import the ZaimeaLabs\Aggregate\Aggregate
class and pass along a model or query.
::model()
come as it is.
::query()
allow you to use additional filter like where()
.
// Totals per month $model = Aggregate::model(User::class) ->between( start: now()->startOfYear(), end: now()->endOfYear(), ) ->perMonth() ->count(); // Count users register per year, results are grouped per month $query = Aggregate::query(User::whereNotNull('email_verified_at')) ->between( start: now()->startOfYear()->subYears(10), end: now()->endOfYear(), ) ->perYear() ->count(); // Average user calendar activity where record type is work with a over a span of 11 years, results are grouped per year $query = Aggregate::query(Record::where('type', 'work')) ->dateColumn('scheduled_at') ->between( start: now()->startOfYear()->subYears(10), end: now()->endOfYear()) ->perYear() ->sumTime('duration');
Date Column
If your column is not created_at
just use dateColumn('pointed_date_column')
->dateColumn('pointed_date_column')
Aggregates
You can use the following aggregates:
Intervals
You can use the following aggregates intervals: