timothepearce / laravel-quasar
Laravel Time Series provides an API to create and maintain projected data from you Eloquent models, and represent them as time-series.
Fund package maintenance!
TimothePearce
Requires
- php: ^8.0
- illuminate/contracts: ^9.0
Requires (Dev)
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-02-10 12:10:43 UTC
README
Build your time series with ease
About
Laravel Time Series provides an API to projects data from your Eloquent models, and convert them to time series.
Documentation
The full documentation can be found here.
Usage
Installation
composer require timothepearce/laravel-time-series
Migrate the tables
php artisan migrate
Create a Projection
php artisan make:projection MyProjection
Make a model projectable
When you want to make your model projectable, you must add it the Projectable
trait and define the $projections
class attribute:
use App\Models\Projections\MyProjection; use TimothePearce\TimeSeries\Projectable; class MyProjectableModel extends Model { use Projectable; protected array $projections = [ MyProjection::class, ]; }
Implement a Projection
When you're implementing a projection, follow theses three steps:
Query a Projection
A Projection is an Eloquent model and is queried the same way, but keep in mind that the projections are all stored in a single table. That means you'll have to use scope methods to get the correct projections regarding the period you defined earlier:
MyProjection::period('1 day') ->between( today()->subDay(), // start date today(), // end date ) ->get();
Query a time series
To get a time series from a projection model, use the toTimeSeries method:
MyProjection::period('1 day') ->toTimeSeries( today()->subDay(), today(), );
Note that this method fill the missing projections between the given dates with the default content you defined earlier.
Credits
License
The MIT License (MIT). Please see License File for more information.