From bb6be95ebbfcad8c558ca0c7504efaa69e28e511 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 4 Jun 2025 12:59:37 +0200 Subject: [PATCH] [Doctrine] Show nullable arguments in EntityValueResolver --- doctrine.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/doctrine.rst b/doctrine.rst index 6abf5fa7928..ae7cb259628 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -650,7 +650,21 @@ automatically! You can simplify the controller to:: } That's it! The attribute uses the ``{id}`` from the route to query for the ``Product`` -by the ``id`` column. If it's not found, a 404 page is generated. +by the ``id`` column. If it's not found, a 404 error is thrown. + +You can change this behavior by making the controller argument optional. In that +case, no 404 is thrown automatically and you're free to handle the missing entity +yourself:: + + #[Route('/product/{id}')] + public function show(?Product $product): Response + { + if (null === $product) { + // run your own logic to return a custom response + } + + // ... + } .. tip::