where('sla_deadline', '<', now()) ->with(['service', 'integrationRequest.agent']) ->get(); foreach ($overdueTasks as $task) { // Log for audit Log::warning("SLA Overdue for task ID {$task->id} (Service: {$task->service->name})"); // Notify service members $serviceRole = $task->service->name; $users = \App\Models\User::role($serviceRole)->get(); \Illuminate\Support\Facades\Notification::send($users, new \App\Notifications\SlaOverdueNotification($task)); // Also notify RH $rhUsers = \App\Models\User::role('RH')->get(); \Illuminate\Support\Facades\Notification::send($rhUsers, new \App\Notifications\SlaOverdueNotification($task)); } } }