Skip to content

[Doctrine] Show nullable arguments in EntityValueResolver #21044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion doctrine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down