Replies: 1 comment 2 replies
-
When you want to get the currently authenticated user making this request inside the form request class, you can do so via |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a question about dependency injection in Laravel.
I want to access a
User
model instance that indicates currently manipulating user data inFormRequest
to reduce controller size.For example, to check an email is unique except for the current user; I wrote like this.
FormRequest
implementationAnd I use this as a type hinting in a controller.
Controller
implementationI supposed Laravel's DI injects a currently manipulating
User
model object intoUpdateEmailRequest
by a relation between the controller and it.But when I tried them, injected
$user
instance was a brand newUser
one.I escaped this problem by accessing a request via route definition like these.
Route definition
In
UpdateEmailRequest
classHowever, I think this workaround is not a good idea because this means
UpdateEmailRequest
depends on a route definition.Do you have any ideas for getting a
User
instance and keeping sparse connections among classes?I beg your help, thank you.
Beta Was this translation helpful? Give feedback.
All reactions