security->isGranted('ROLE_ADMIN')) { throw new AccessDeniedException('Access denied: ROLE_ADMIN required.'); } $address = $this->addressRepository->findById($id); if (null === $address) { throw new InvalidArgumentException(sprintf('Address with ID %d not found.', $id)); } $this->entityManager->remove($address); $this->entityManager->flush(); return json_encode(['success' => true, 'message' => sprintf('Address #%d deleted.', $id)]); } }