• Reading time ~ 1 min
  • 17.05.2023

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:

$model->repeat()->daily()->startsAt(Carbon::make());

You can also set an end date when the recurring model should stop:

$model->repeat()->daily()->endsAt(
    Carbon::make('2023-06-01')
);

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.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297