Laravel 7 will support direct customization of implicit routing model binding in routing definitions
Route::get('/posts/{post:slug}', function (Post $post) { // ... });
<? php class Post extends Model { /** * Get the route key for the model. * * @return string */ public function getRouteKeyName() { return 'slug'; } }
Route::get('/posts/{post:slug}', function (Post $post) { // ... }); // Or you could use the default `{post}` here... Route::get('/admin/posts/{post:id}/edit', function (Post $post) { // ... });
laravel new example --dev
Note: This article is compiled from Larravel News. The original link is: https://laravel-news.com/implicit-route-model-binding