requireRole($this->security, 'ROLE_GESTIONNAIRE'); $site = $this->sites->find($siteId); if (!$site) { $this->mcpError('not_found', "Site not found: {$siteId}"); } $machine = new Machine(); $machine->setName($name); $machine->setSite($site); if ('' !== $reference) { $machine->setReference($reference); } if ('' !== $prix) { $machine->setPrix($prix); } foreach ($constructeurIds as $cId) { $c = $this->constructeurs->find($cId); if (!$c) { $this->mcpError('not_found', "Constructeur not found: {$cId}"); } $machine->addConstructeur($c); } $this->em->persist($machine); $this->em->flush(); return $this->jsonResponse([ 'id' => $machine->getId(), 'name' => $machine->getName(), ]); } }