diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index fe37aba..834391a 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -45,6 +45,9 @@ class PostController extends AbstractController public function post(Request $request, string $slug): Response { $post = $this->getDoctrine()->getRepository(Post::class)->findOneBy(array('slug' => $slug)); + if (!$post) { + throw $this->createNotFoundException("Post not found"); + } $form = $this->commentFormGenerator($post); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) {