diff --git a/src/Controller/NotificationsController.php b/src/Controller/NotificationsController.php index 5c25cf70b2759effd41a006038563ae8564d84d6..bc8e7a4104fb7fd580d475587e1ce4577be361dd 100644 --- a/src/Controller/NotificationsController.php +++ b/src/Controller/NotificationsController.php @@ -26,4 +26,17 @@ class NotificationsController extends AbstractController 'notifs' => $notifs ]); } + + #[Route('/notificationsSupprimer/{id}', name: 'app_notifications_supprimer')] + public function supprimer($id): Response + { + $entityManager = $this->doctrine->getManager(); + $notif = $entityManager->getRepository(Notification::class)->find($id); + if ($notif) + $entityManager->remove($notif); + $entityManager->flush(); + + $notifs = $entityManager->getRepository(Notification::class)->findBy(['user_id' => $this->getUser()]); + return $this->redirectToRoute('app_notifications'); + } } diff --git a/templates/notifications/index.html.twig b/templates/notifications/index.html.twig index 00328b7ccb5cedfbb3bf85f3c0b76bf1732bf216..923156b129a1a72a22a5b90375a3db50a4e8d201 100644 --- a/templates/notifications/index.html.twig +++ b/templates/notifications/index.html.twig @@ -21,6 +21,7 @@ <td>{{ notif.date|date('d/m/y') }}</td> <td>{{ notif.type }}</td> <td>{{ notif.description }}</td> + <td><a href="{{ path('app_notifications_supprimer', {'id': notif.id}) }}"><button>Supprimer</button></a> </tr> {% endfor %} {% else %}