Category: Laravel, Laravel, PHP, PHP, api, api, javascript, javascript

· October 3, 2020 · ⋆ Laravel Essentially, if you want to inject something which can be swappable anytime, you can do this by “biding” that into the service container.

So, what we can do is define an interface that contains certain methods called payment and discount like so. And now if we want to use a payment method in our application, we can create a class for that payment method which will implement the App\Payment\Contract\PaymentInterface.

And if we want to resolve App\Payment\Contract\PaymentInterface to App\Payment\Stripe in the PurchaseController controller, we can define the binding like so.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners