assignee; if (!$assignee || !$this->enabled('assigned')) { return; } $assignee->notify(new RequestAssignedNotification($request)); } public function notifyStatusChanged(ServiceRequest $request): void { if (!$this->enabled('status_changed')) { return; } $request->client?->notify(new RequestStatusChangedNotification($request)); } public function notifyCommentAdded(ServiceRequest $request, User $author): void { if (!$this->enabled('comment_added')) { return; } $recipients = collect([$request->client, $request->assignee]) ->filter() ->reject(fn (User $user) => $user->id === $author->id); /** @var User $recipient */ foreach ($recipients as $recipient) { $recipient->notify(new RequestCommentAddedNotification($request, $author)); } } public function notifyOverdue(ServiceRequest $request, Collection $managers): void { if (!$this->enabled('overdue')) { return; } $recipients = collect([$request->assignee])->filter()->merge($managers); /** @var User $recipient */ foreach ($recipients->unique('id') as $recipient) { $recipient->notify(new RequestOverdueNotification($request)); } } public function notifySlaWarning(ServiceRequest $request, Collection $managers): void { if (!$this->enabled('sla_warning')) { return; } $recipients = collect([$request->assignee])->filter()->merge($managers); /** @var User $recipient */ foreach ($recipients->unique('id') as $recipient) { $recipient->notify(new SlaWarningNotification($request)); } } private function enabled(string $key): bool { $map = $this->settingsService->emailNotifications(); return (bool) ($map[$key] ?? true); } }