Answer the question
In order to leave comments, you need to log in
Facades, helpers, dependency injection - what to use where?
Greetings,
Is there any established practice on this issue?
For example, dependency injection only in controllers and facades only in views and models? As for the helpers, I'm generally confused. For me, helpers have always been associated with a kind of self-sufficient functions, but here everything is somehow mixed up and what is the secret meaning of this I don’t understand.
return View::make('profile');
return view('profile');
Answer the question
In order to leave comments, you need to log in
I don't think. Just convenience. DI can be used not only in controllers, but in general in any classes, provided that this class is resolved through the container (well, so as not to resolve dependencies with handles).
https://laravel.com/docs/7.x/container
In addition to "convenience" is there some other secret meaning?It is very convenient and simple for beginners, why is it difficult as a clap and did
For me, helpers have always been associated withAs Arshavin once said (paying his career because of these words) "Your expectations are your problems" :)
Facades, helpers, app(Dep::class), resolve(Dep::class) and similar things are OK until you want to separate the logic from the framework (to migrate to another framework or another programming language) .
Unit testing without binding to a container is also much more convenient.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question