›
byrcsc/laravel-checklist · 1.x
Persist a recurring checklist schedule and run its generator through Laravel's scheduler.
A Schedule creates future checklists from one template. Add one when the work
must recur without an operator starting every checklist by hand.
use ByRcsc\LaravelChecklist\Enums\Frequency;
use ByRcsc\LaravelChecklist\Enums\OverlapPolicy;
use ByRcsc\LaravelChecklist\Models\Schedule as ChecklistSchedule;
$schedule = new ChecklistSchedule([
'template_id' => $template->id,
'frequency' => Frequency::Weekly,
'day_of_week' => 1, // Monday, using Carbon's 0 to 6 convention
'timezone' => 'Australia/Brisbane',
'next_due_at' => now('Australia/Brisbane')
->next('Monday')
->setTime(6, 0)
->utc(),
'overlap_policy' => OverlapPolicy::SkipWhileOpen,
'active' => true,
]);
$schedule->subject()->associate($vehicle);
$schedule->assignee()->associate($driver);
$schedule->save();The assignee and subject are optional polymorphic relations. The schedule copies them onto each generated checklist.
For weekly schedules, set day_of_week from 0 for Sunday through 6 for
Saturday. If omitted, the model derives it from next_due_at when saved.
For monthly schedules, set day_of_month from 1 through 31. If omitted,
the model derives the day from next_due_at.
For every-N-days schedules, set a positive n_days. A zero or missing value is
treated as one day by the recurrence calculation, but application validation
should reject that ambiguous input.
Daily schedules need no supporting field.
use Illuminate\Support\Facades\Schedule;
Schedule::command('checklist:generate-due')->everyFifteenMinutes();The command creates due instances, advances schedules, and then announces due-soon and overdue checklists. Schedule Laravel's scheduler process in the normal way for the deployment environment.
Use AlwaysCreate when every occurrence must exist even if earlier work is
unfinished.
Use SkipWhileOpen when only one pending or in-progress checklist should
exist for this schedule. A skipped occurrence still advances to the next due
time.
$schedule->update(['active' => false]);
$schedule->update(['active' => true]);Inactive schedules are ignored. A null next_due_at is also ignored. Set a
future or past due time when resuming.