Skip to content

Commit bb6be95

Browse files
committed
[Doctrine] Show nullable arguments in EntityValueResolver
1 parent f5af7bd commit bb6be95

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

doctrine.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,21 @@ automatically! You can simplify the controller to::
650650
}
651651

652652
That's it! The attribute uses the ``{id}`` from the route to query for the ``Product``
653-
by the ``id`` column. If it's not found, a 404 page is generated.
653+
by the ``id`` column. If it's not found, a 404 error is thrown.
654+
655+
You can change this behavior by making the controller argument optional. In that
656+
case, no 404 is thrown automatically and you're free to handle the missing entity
657+
yourself::
658+
659+
#[Route('/product/{id}')]
660+
public function show(?Product $product): Response
661+
{
662+
if (null === $product) {
663+
// run your own logic to return a custom response
664+
}
665+
666+
// ...
667+
}
654668

655669
.. tip::
656670

0 commit comments

Comments
 (0)