I usually use facade, however you can alway use
App::make()
So using App::make() in another route or model you would use?
$lot = App::make('Acme\Repositories\Lot\LotRepositoryInterface');
I just started reading that Facades weren't ideal for testing so I was trying to avoid them!
leoden said:
So using App::make() in another route or model you would use?
$lot = App::make('Acme\Repositories\Lot\LotRepositoryInterface');
If a class is instantiated by the IoC container the interface can just be injected. If using a route closure you'll have to use the App::make() but in another class just inject the interface like you would in a controller.
leoden said:
I just started reading that Facades weren't ideal for testing so I was trying to avoid them!
Facades are no worse for testing than using a closure directly in the route, its best to stick to controllers. Any facade can be partially mocked with Mockery by calling FacadeName::respondsTo('something')... but its not as nice as injecting all dependencies. Injecting all controller dependencies can get very cumbersome though.
Thanks for the answers guys much appreciated!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community