- Notifications
You must be signed in to change notification settings - Fork 11.7k
Closed
Description
Laravel Version
11.22.0
PHP Version
8.2.16
Database Driver & Version
No response
Description
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.
Steps To Reproduce
class SomeController { public function someMethod( #[CurrentUser] ?User $user ): void { dd($user); } }When executing this code without being logged in (having no available user), the $user will contain an empty model.
EranNL
Metadata
Metadata
Assignees
Labels
No labels