Route Model Binding: Cleaner Controller Code
Automatically inject models into controllers using Laravel’s route model binding feature.
Sarah Collins
November 5, 2025
5.2k172
Route model binding removes repetitive database lookups from your controllers.
## Traditional approach
```php
public function show($id) {
$post = Post::findOrFail($id);
}
```
## With model binding
```php
public function show(Post $post) {
return view('posts.show', compact('post'));
}
```
Route:
```php
Route::get('/posts/{post}', [PostController::class, 'show']);
```
Laravel sees {post} and loads the model automatically.
## Flow
```mermaid
flowchart LR
A[/posts/5] --> B[Router]
B --> C[Load Post]
C --> D[Controller(Post)]
```
This keeps controllers shorter and more readable.
In the next tutorial, we will secure mass assignment using $fillable.
#Laravel#Routing#Eloquent#Intermediate