/** * @Route("/admin/deleteclient/{id}",name="deleteclient") * @ParamConverter("client", class="AppBundle:Client") * @Security("has_role('ROLE_ADMIN')") */ public function deleteClient(Client $client) { $em = $this->getDoctrine()->getManager(); if ($insurances = $client->getInsurances()) { foreach ($insurances as $insurance) { if ($todo = $insurance->getTodo()) { $em->remove($todo); } $em->remove($insurance); } } if ($user = $client->getSingleUser()) { $em->remove($user); } $em->remove($client); $em->flush(); return $this->redirectToRoute('clientslist'); }