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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners