houseoftech / laravel-recurring
simshaun/recurr integration for Laravel/Eloquent.
Requires
- php: ^7.2
- illuminate/support: ^6.0
- simshaun/recurr: ^3.0
Requires (Dev)
- graham-campbell/testbench: ^3.3
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2025-03-08 16:30:23 UTC
README
Installation
Require this package, with Composer, in the root directory of your project.
$ composer require houseoftech/laravel-recurring
Note: If using with Laravel 5.x, require version 1.
$ composer require houseoftech/laravel-recurring:1.5.3
This package includes a publishable asset. Publishing will copy the config to your project so it can be modified.
$ php artisan vendor:publish
The config file can be found at config/laravel-recurring.php
.
Usage
<?php namespace App; use BrianFaust\LaravelRecurring\Traits\RecurringTrait; use Illuminate\Database\Eloquent\Model; class Task extends Model { use RecurringTrait; }
Route::get('/', function () { $task = App\Task::first(); $task->recurr()->first(); $task->recurr()->last(); $task->recurr()->next(); $task->recurr()->current(); $task->recurr()->rule(); $task->recurr()->schedule(); });
Examples
$task = new App\Task(); $task->start_at = '2017/1/1'; $task->until = '2017/12/12'; $task->by_day = 'MO,FR'; $task->frequency = 'WEEKLY'; $task->timezone = 'Europe/Amsterdam'; $start = new DateTime('2017/5/5'); $end = new DateTime('2017/5/15'); print_r($task->recurr()->scheduleBetween($start, $end)); // Using exceptions and inclusions $task->exceptions = ['2017/05/08']; $task->inclusions = ['2017/05/10', '2017/05/11']; print_r($task->recurr()->scheduleBetween($start, $end));
Using Exception and Inclusion Dates Directly from Related Models
Exceptions and inclusions can be passed as a single date string, an array of date strings, or as an Eloquent\Collection
.
The value will be plucked from the date
column.
Example exceptions migration
Schema::create('exceptions', function (Blueprint $table) { $table->increments('id'); $table->integer('event_id')->unsigned(); $table->datetime('date'); $table->timestamps(); });
Assuming Task model has a hasMany relation to Exception, e.g.
public function exceptions() { return $this->hasMany(Exception::class); }
The exceptions can be passed to recurr directly.
$task = App\Task::with('exceptions')->find(1); print_r($task->recurr()->schedule());
Testing
$ phpunit
Security
If you discover a security vulnerability within this package, please send an e-mail to Brian Faust at hello@brianfaust.me. All security vulnerabilities will be promptly addressed.