select(['id']) ->where('is_active', true) ->whereHas('roles', fn ($q) => $q->whereIn('name', $roles)) ->get(); if ($additionalUser && ! $users->contains('id', $additionalUser->id)) { $users->push($additionalUser); } $users->each(function (User $user) use ($title, $body, $url) { try { $user->notifications()->create([ 'title' => $title, 'body' => $body, 'url' => $url, ]); $user->notify(new WebPushNotification($title, $body)); } catch (\Exception $e) { Log::error("Gagal mengirim notifikasi ke user {$user->id}: {$e->getMessage()}"); } }); } }