Category: Laravel

Laravel’s route model binding is a very powerful feature. First of all, let’s take a look, how to bind a contract to a model in the container. This is a very simple process, all we need to do is call the bind() method in our service provider.

So, let’s create an explicit route-model binding in one of our service providers, but instead of resolving a model directly, let’s use the container to get the bound implementation: So in our routes, we can type-hint our contract and it’ll return with the desired model property: You may ask, why is this even useful? Well, most of the cases this is not the best pattern we can go for, however, sometimes this can provide an extra layer of flexibility.
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