I have \App\Repository\ProductRepositoryInterface and a class that implements that interface \App\Repository\ProductRepository.
If I create an invocable controller and request ProductRepositoryInterface like this:
/**
* Handle the incoming request.
*/
public function __invoke(
Request $request,
ProductRepositoryInterface $productRepository
) {
}
Is there a way I tell Laravel service container implementation for ProductRepositoryInterface just for that concrete controller?
Please note that
// To global as it sets implementation for all classes - I need only for one controller's method
$this->app->bind(ProductRepositoryInterface::class, ProductRepository::class, true);
or
// Works only when I inject ProductRepositoryInterface into __construct
$this->app->when(Controller::class)
->needs(ProductRepositoryInterface::class)
->give(ProductRepository::class);
Is there a way to achieve the above?
Thanks in advance!