Welcome!
It's ugly...and feels like a hack...but possible I think..
You can pass a parameter when calling App::make. So basically the closure works as a factory.
interface Test
{
}
class Test1 implements Test
{
}
class Test2 implements Test
{
}
App::bind('Test', function($app, $param = null) {
$classes = ['Test1', 'Test2'];
if ($param && in_array($param,$classes)) {
return App::make($param);
}
return [
'Test1' => new Test1,
'Test2' => new Test2
];
});
Route::get('/', function(){
// to get all Test1 and Test2
$test = App::make('Test');
// to get only Test1
$test = App::make('Test', 'Test1')
dd($test);
exit;
});
It doesn't work magically like c#, but I think you get the idea.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community