diff --git a/src/Service/UserOrganizationService.php b/src/Service/UserOrganizationService.php index cde8f3e..7ac60f9 100644 --- a/src/Service/UserOrganizationService.php +++ b/src/Service/UserOrganizationService.php @@ -207,15 +207,16 @@ readonly class UserOrganizationService $uoEntity = $this->entityManager ->getRepository(UsersOrganizations::class) ->findOneBy(['users' => $user, 'organization' => $organization, 'role' => $roleUser]); -// dd($roleUser); +// dd($uoEntity->getApps()->toArray()); // 1. Remove apps that are no longer selected - foreach ($uoEntity->getApps() as $existingApp) { + foreach ($uoEntity->getApps()->toArray() as $existingApp) { if (!in_array($existingApp->getId(), $selectedApps)) { + $uoEntity->removeApp($existingApp); } } - // 2. Add newly selected apps (your existing logic) + // 2. Add newly selected apps foreach ($selectedApps as $appId) { $appEntity = $this->entityManager->getRepository(Apps::class)->find($appId); if ($appEntity && !$uoEntity->getApps()->contains($appEntity)) {