Sometimes you may wish to resolve Eloquent models using a column other than id. To do so, Laravel 7 allows you to specify the column in the route parameter definition:

Route::get('posts/{post:slug}', function (App\Post $post) {
    return $post;
});

Laravel 7 will automatically scope the query to retrieve the nested model by using its discern the usage of conventions to bet the relationship call on the figure.

For more information on route model binding, please consult the routing documentation.

You may also Like