Support the ongoing development of Laravel.io →
posted 9 years ago
IOC
Last updated 1 year ago.
0

I guess it's a problem in your binding. Cant you show how you did to bind ImageRepositoryInterface to an implementation?

0

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'
		);
	}
}
0

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);
});
0

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);
});
Last updated 9 years ago.
0

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

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.