laravel 5 - How to pass arguments from resolve() to callback specified in give()? -
constructor of class requires instance of class b, constructor in turn takes optional string argument.
i want able specify value of string argument class b constructor when resolving class a. want something in service provider:
$this->app ->when(a::class) ->needs(b::class) ->give(function($argument_for_b /* <-- here */){ return new b($argument_for_b); })
and obtain instance of (assuming has been bound ainterface in container):
$ainstance = resolve(ainterface::class /* how pass argument b? */);
Comments
Post a Comment