whereIn('name', ['Admin', 'Leader']); })->get(); if ($users->isEmpty()) { return; } $now = Carbon::now(); foreach ($users as $user) { // 12 months backward including current month for ($i = 0; $i < 12; $i++) { $month = $now->copy()->subMonths($i); $isCurrentMonth = $i === 0; $payroll = Payroll::factory() ->for($user) ->withPeriodMonth($month->format('Y-m')) ->create([ 'is_paid' => $isCurrentMonth ? IsPaid::NOT_PAID : IsPaid::PAID, 'paid_at' => $isCurrentMonth ? null : $month->copy()->addDays(28), 'created_at' => $month->copy()->addDays(20), 'updated_at' => $month->copy()->addDays(20), ]); // Create some adjustments PayrollAdjustment::factory() ->count(rand(0, 3)) ->create([ 'payroll_id' => $payroll->id, 'created_at' => $month->copy()->addDays(22), 'updated_at' => $month->copy()->addDays(22), ]); } } } }