DEV Community

Discussion on: Laravel Service Container and Service Providers Explained

Collapse
 
saaberdev profile image
Mahfuzur Rahman Saber

How do I retrieve right service based on request parameter ?

Lets say i have a share button and it has sub buttons such as Facebook, LinkedIn and et cetera.

if param is fb it will use fbservice and if param is linkd it will use linkedin service ??

I used it in this manner but i end up with dependency injection resolve error when i try to return back to my site which is a confirmation page within the same controller.

Collapse
 
tutanramon profile image
TutanRamon

I am wondering the same thing. And what if somebody clicks on a "share on all social media" ?

Collapse
 
fhsinchy profile image
Farhan Hasin Chowdhury

@saaberdev and @tutanramon Contextual Binding may come in handy in situations when you want to retrieve instances based on a condition - laravel.com/docs/9.x/container#con...