subMonths(rand(1, 12))->subDays(rand(0, 30)); $endDate = (clone $startDate)->addDays(rand(5, 90)); // Course duration between 5 to 90 days $numDays = $startDate->diffInDays($endDate) + 1; OnlineCourse::create([ 'faculty_id' => rand(1, 5), 'department_id' => rand(1, 5), 'course' => $courses[array_rand($courses)], 'offered_by' => $offeredBys[array_rand($offeredBys)], 'start_date' => $startDate->format('Y-m-d'), 'end_date' => $endDate->format('Y-m-d'), 'num_days' => $numDays, 'proof' => null, // Proof left null ]); } } }