schedule); if (!$valid) { dd($maintenance->schedule); return; } $cron = new CronExpression($maintenance->schedule); $maintenancePlanned = $maintenance->history()->create([ 'start_at' => $cron->getNextRunDate(null, 2) ]); $maintenancePlanned->refresh(); $tasks = $maintenancePlanned->tasks; if(!empty($tasks)){ dd($tasks); foreach ($tasks as $key => $task) { $maintenancePlanned->tasks()->create([ 'host_id' => $task->host_id, ]); } } } die(); } }