Monday, March 20, 2017

How to properly use Laravel Service Container?

Ok , I've watched the Laracast videos on the topic and also have read the documentation , still I miss the core point here . Let's say we have the following structure :

enter image description here

So I understood how to create a service provider, bind a class to the service container and resolve it later. But what if "MyCustomClass" binding has to be replaced let's say by "\App\SomeOtherClass". That would lead to an exception of missing "SomeOtherClass" if I don't reference it. This leads me to the question: "What's the point of using service container, since I still have to reference the bound class again ? What am I doing wrong here ?



via user3102290

Advertisement