$userId, 'title' => $title, 'message' => $message, 'type' => $type, 'url' => $url, 'reference_type' => $referenceType, 'reference_id' => $referenceId, ]); } public function notifyUsers(iterable $userIds, string $title, string $message, string $type = 'info', ?string $url = null, ?string $referenceType = null, ?int $referenceId = null): void { foreach ($userIds as $userId) { $this->notifyUser((int) $userId, $title, $message, $type, $url, $referenceType, $referenceId); } } public function notifyRole(string $role, string $title, string $message, string $type = 'info', ?string $url = null, ?string $referenceType = null, ?int $referenceId = null): void { $userIds = User::query()->where('role', $role)->pluck('id'); $this->notifyUsers($userIds, $title, $message, $type, $url, $referenceType, $referenceId); } public function unreadForUser(int $userId): Collection { return UserNotification::query() ->where('user_id', $userId) ->whereNull('read_at') ->latest('id') ->get(); } }