Sometimes you need data to repeat on a date interval, like a standing calendar appointment, a weekly event, or a payment schedule. The Recurring Models package for Laravel is the ultimate solution for adding recurring functionality to your Laravel Models:
$model->repeat()->daily();$model->repeat()->weekly();$model->repeat()->weekly()->on(['sunday', 'monday', 'tuesday']);
When you repeat a model, the start date is calculated using a
startsAt() method on the model. Or you can specify the start date as follows:
You can also set an end date when the recurring model should stop:
And once you have recurring data, you can retrieve it using the package's provided scopes:
$tasks = Task::whereOccurresOn(Carbon::make('2023-05-01'))->get();// Between$tasks = Task::whereOccurresBetween(Carbon::make('2023-05-01'),Carbon::make('2023-05-30'))->get();
This new package could serve as an excellent inspiration for simplifying models that need repeating with dates. To get started with this package, check out the source code. on GitHub.
Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.