Route-Model Binding in Laravel 5.4

Ok, I'll admit it: I have found an new (for me, that is) feature and now I want to tell everybody about it. It's just a phase, bear with me ...

The Problem

It's not really something new when you are writing an webapp of any sort: You want to show a detail-page for a specific entry of some sort and you will have a URL that in one way or another contain the ID to fetch the entry from the database, something like /things/{thing_id}. Doing this manually will end up in a log of code that you'll write over and over again: your controller method will check for something like a field in $_GET and redirect you to a 404 page if either the field is empty or something along the lines of $_GET[thing_id] cannot be found in the database. So that's somewhat tedious.

Route-Model Binding to the rescue

Laravel provides a nice way of dealing with this situation: whenever you create a route like /things/{thing} and "thing" is also a model in your application you will have $thing available to you in the controller method you are calling for this route or any anonymous function you are binding to this route. Should the ressource not be found in the database you are going to be redirected to a 404 page.

This is of course quite handy for CRUD apps, that is to say most of what we build all the time, or something like fleshing out an API really quickly.

The feature is of course well documented over here: https://laravel.com/docs/5.4/routing#route-model-binding
There is also a video in the Laravel from scratch series over at Laracasts: https://laracasts.com/series/laravel-from-scratch-2017/episodes/9