You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are using the new ContextualAttribute to get the CurrentUser in our controller methods. This works fine, until there is no user in the guard.
The function resolve in the attribute correctly returns null, but the Container then resolves the parameter to a new User instance if there is a type-hint for a User on the parameter. This even happens when the parameter type is indicated as optional.
This could also potentially "break" some edge cases in the new features from this PR: #53080
When you have an optional parameter in your URL, I guess you would not want an empty model when trying to resolve it, it would be better to resolve to null in my opinion.
Laravel Version
11.22.0
PHP Version
8.2.16
Database Driver & Version
No response
Description
We are using the new
ContextualAttribute
to get theCurrentUser
in our controller methods. This works fine, until there is no user in the guard.The function
resolve
in the attribute correctly returnsnull
, but theContainer
then resolves the parameter to a newUser
instance if there is a type-hint for aUser
on the parameter. This even happens when the parameter type is indicated as optional.Steps To Reproduce
When executing this code without being logged in (having no available user), the
$user
will contain an empty model.The text was updated successfully, but these errors were encountered: