Category: Laravel, PHP

When I first started working with Laravel, one of the very first piece of code that I came across was similar to following: So when I went to URL /post/1, the Post with id 1 was available inside the controller as variable $post. If I entered a URL with id that did not existed in the Database, I was even redirected to a 404 Page.

Later on I came to know that this particular feature is known as Route Model Binding.

Without Route Model Binding, our code would have looked something as follows: With Route Model Binding, it is super compact without affecting the readability.

We then need to tell Router that we are going to use Explicit Binding for this Route.
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