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

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