joaorbrandao / laravel-intervals
This package creates a simple way of adding time intervals to your projects.
Requires
- php: >=7.2.5
- ext-json: *
- illuminate/support: ^7.0
- nesbot/carbon: ^2.25
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^5.2
- phpunit/phpunit: 8.*
This package is auto-updated.
Last update: 2024-11-05 08:37:24 UTC
README
This package creates a simple way of adding time intervals to your projects.
Installing
composer require joaorbrandao/laravel-intervals
Publish the package into your application.
php artisan vendor:publish --provider=Joaorbrandao\LaravelIntervals\LaravelIntervalsServiceProvider
A folder containing some filters will be published in "app/LaravelIntervals".
Feel free to modify/delete them if you want!
Usage
Create a new Interval
This command will create a new interval in "app/LaravelIntervals".
php artisan make:interval FirstDayOfLastWeek
Setup the Interval
Each time interval has 5 properties: start, end, enabled, id and name.
After running the command to create the interval, you must change the start and end to match with the interval name.
<?php namespace App\LaravelIntervals; use Joaorbrandao\LaravelIntervals\Contracts\Interval; final class FirstDayOfLastWeek implements Interval { public function resolve() { return [ 'start' => now()->subWeek()->startOfWeek()->startOfday(), 'end' => now()->subWeek()->startOfWeek()->endOfDay(), 'enabled' => true, 'id' => 'firstDayOfLastWeek', 'name' => 'first_day_of_last_week', ]; } }
Make use of it!
One of the ways of using this is with the Facade. The result of the facade is the time interval set defined in the configuration file with the start and end properties being Carbon instances.
LaravelIntervals::last365Days(); // Return Joaorbrandao\LaravelIntervals\Interval^ {#382 +end: Illuminate\Support\Carbon @1571693543^ {#767 date: 2019-10-21 21:32:23.050513 UTC (+00:00) } +id: "last365Days" +name: "last_65_days" +start: Illuminate\Support\Carbon @1540157543^ {#768 date: 2018-10-21 21:32:23.050440 UTC (+00:00) } }
License
laravel-intervals is an open-source laravel package licensed under the MIT license.