Laravel

Laravel Route Model Binding: Cleaner Controllers

January 16, 2026 1 min read 16 views

Cleaner routes with model binding:

Implicit Binding

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

Custom Key

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

In Model

public function getRouteKeyName()
{
    return 'slug';
}

Scoped Binding

Route::get('/users/{user}/posts/{post:slug}', function (User $user, Post $post) {
    return $post;
})->scopeBindings();
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!