I'm not sure but I'm using this and it works well.
$this->app->share(function($app)
{
return new ViewData;
});
App::singleton() for binding a concrete class to the container as its abstract like:
class ConcreteClass implements AbstractInterface {};
And in some constructor:
public function __construct(AbstractInterface $dependency)
{
}
Then if you use:
App::singleton('AbstractInterface', 'ConcreteClass');
Laravel will inject a single instance of the ConcreteClass into the constructor above, this will useful for injecting an adapter. When there are number of adapter implemented same interface, and in your client script just want to 'know' about the interface (abstract), not the specifiec ones (concrete), and using App::singleton() will help you switch to the specific adapter at run-time. This mechanism can be applied to strategy, driver, ... as well.
In your case, using
App::bindShared('viewdata', function(){
App::make('ViewData');
});
is preferred.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community