Skip to content
laravelphp

Laravel 12 - Route Model Binding with Scoping

Automatically inject model instances into routes with scoped bindings for multi-tenant applications

<?php

// In routes/web.php
Route::get('/users/{user}/posts/{post}', function (User $user, Post $post) {
    return $post;
})->scopeBindings(); // Laravel 12 automatically scopes $post to $user

// Alternative: Implicit scoping in route definition
Route::get('/users/{user}/posts/{post:slug}', [PostController::class, 'show'])
    ->scopeBindings();

// In your Post model
public function user(): BelongsTo
{
    return $this->belongsTo(User::class);
}