Answer the question
In order to leave comments, you need to log in
Why is Dependency Injection implemented in Laravel via function parameters?
Hello.
It didn’t immediately dawn on me that in Laravel, if you write something like public function some_func(Request $request)
$request in the method parameters, a class from a suitable service provider will be automatically created. According to the logic of past programming, on the contrary, I had to pass the $request variable of the Request class to this some_func when called.
Why is it done this way? Because it's confusing. Why not get the necessary objects by the type of facades or some other function that would return the requested values from anywhere.
What is the advantage of passing in the parameters of methods?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question