Commit 4a57a333 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Auto-generate sessions when schedule is saved

When a training schedule is created or updated, immediately generate
sessions for the next 7 days so trainers see today's sessions without
waiting for the nightly cron.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent bcd1cc8d
......@@ -4,7 +4,9 @@
use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Shared\Traits\HasUuid;
use App\Domain\Training\Services\SessionGeneratorService;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
......@@ -13,6 +15,19 @@ class TrainingSchedule extends Model
{
use BelongsToAcademy, HasUuid;
protected static function booted(): void
{
static::saved(function (TrainingSchedule $schedule) {
if ($schedule->is_active && $schedule->group) {
app(SessionGeneratorService::class)->generate(
$schedule->group,
Carbon::today(),
Carbon::today()->addDays(7),
);
}
});
}
protected $fillable = [
'academy_id', 'training_group_id', 'facility_id',
'day_of_week', 'start_time', 'end_time',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment