Category: Laravel

What I’m writing in this article is actually can be read on Laravel’s official documentation about Service Container. It works for me, and I hope it also works for you. For example, suppose that: Normally, without dependency injection technique, you will do something like this: If you happen to use object of class A in many places, then it will give you many line of codes that’s actually not part of your main application logic.

Now, wherever you need aHelpSpot\API object in your code, you can get it by simply type: See that you don’t need to bother about making an HttpClient to make the object, Laravel handles it for you.

For example, the code may look like this: So to make an object of HelpSpot\API, Laravel will automatically look for how it resolves and found out that it needs an object of HttpClient to be resolved first.

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Community Partners