Laravel’s service container is one of the most important pieces of the framework yet it gets so little attention from a lot of developers.
So in this article, I’ll take you through step by step in understanding this magical concept.
A simplified IoC container can be written as follows: You can bind any data to this container using the bind() method: You can bind classes to this container by passing a callback function that returns an instance of the class as the second argument.
In that case, you can do something as follows: Once you bind a piece of data to the container, you can ask for it whenever necessary.
In the example above, the LinkedInService class implements an interface, so you have to bind the interface to an implementation of the class.