I am a beginner on Symfony 4 and after having followed some tutorials, I am working on a project to improve myself!
It is an event manager with registrations of participants with a back office. As a visitor, I can register for one or more events from a select list of a bootstrap form. Once registered, the administrator can access his back office and see who has registered in this or that event by selecting a specific event and view the list.
My problem is that if the administrator decides to remove a participant from an event, the participant is deleted in the database and therefore all the events to which it has registered. While I would like it to be removed only from the event in question.
I think I need to create a query in the repository file of my event ...
Here are some parts of the code that I think is useful.
My Entity Participant.php who has a relationship ManyToMany:
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Event", inversedBy="participants")
*/
private $workshops;
Entity Event.php file :
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Participant", mappedBy="workshops")
*/
private $participants;
And in one of my controllers, here is the function that removes the participant from all events :
/**
* @Route("/admin/delete_participant/{id}", name="delete_participant")
*/
public function deleteParticipant(EntityManagerInterface $manager, Participant $participant) {
$manager->remove($participant);
$manager->flush();
$this->addFlash('danger', "Participant deleted");
return $this->redirectToRoute("admin_page", [
'participant' => $participant,
]);
}
I have to create a custo request but I block on it.
How do I solve this problem?