I guess it's a problem in your binding. Cant you show how you did to bind ImageRepositoryInterface to an implementation?
I can indeed. Here's how I bind it. It seems to work for other repo's and works for Image independently just not when injected to another repo. Thanks for the help
class AppServiceProvider extends ServiceProvider{
public function register()
{
$this->app->bind(
'App\Repositories\Product\ProductRepositoryInterface',
'App\Repositories\Product\DbProductRepository'
);
$this->app->bind(
'App\Repositories\ShopCategory\ShopCategoryRepositoryInterface',
'App\Repositories\ShopCategory\DbShopCategoryRepository'
);
$this->app->bind(
'App\Repositories\Image\ImageRepositoryInterface',
'App\Repositories\Image\ImageRepository'
);
}
}
In theory, it should work... Maybe a typo, but I didn't find.
Anyway, you can try to bind your ImageRepository outside the service provider, something like this in your routes.php:
App::bind('App\Repositories\Image\ImageRepositoryInterface', function($app)
{
return new App\Repositories\Image\ImageRepository;
});
or, try this in a test route, to make sure your bind is working:
Route:get('test', function(){
$class = App::make('App\Repositories\Image\ImageRepositoryInterface');
dd($class);
});
In theory, it should work... Maybe a typo, but I didn't find.
Anyway, you can try to bind your ImageRepository outside the service provider, something like this in your routes.php:
App::bind('App\Repositories\Image\ImageRepositoryInterface', function($app)
{
return new App\Repositories\Image\ImageRepository;
});
or, try this in a test route, to make sure your bind is working:
Route:get('test', function(){
$class = App::make('App\Repositories\Image\ImageRepositoryInterface');
dd($class);
});
Unfortunately that doesn't work either. The only way I've found to do it is to inject the interface in to the controller and then pass that to the repository that requires it.
Seems like a poor way to do it though.
Cheers
Ok so I don't think it's ideal but calling the full repo namespace in the function that needs it has got it working so:
function needsImageClass()
{
$image = new \App\Repositories\Image\ImageRepository();
}
If anyone has a better solution I'd love to hear it.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community