B
B
barma0012020-07-26 06:53:47
Laravel
barma001, 2020-07-26 06:53:47

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');


Well, a holivar question is the question - why introduce so many possibilities for obtaining the same total result? In addition to "convenience" is there some other secret meaning?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya, 2020-07-26
@New_Horizons

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

M
Maxim Fedorov, 2020-07-26
@Maksclub

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 with
As Arshavin once said (paying his career because of these words) "Your expectations are your problems" :)
Yes, everything is covered with this magic, in fact, Laravel implemented its own language, which made it understandable and convenient for crowds "programmers" and for quickly stamping monotonous logic
In large projects, the choice still falls on DI:
Stop Using Facades
https://blog.amezmo.com/replacing-your-facades-wit...
Here are some more features from Kirill Nesmeyanov with timing:
https://youtu.be/QHLZohh7Tkw?t=2203

A
Alex Wells, 2020-07-26
@Alex_Wells

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 question

Ask a Question

731 491 924 answers to any question