Skip to main content
Laravel Output Prediction Hard +35 XP

Route Model Binding

What is $post in this route?

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

What is the output?

Show answer and explanation

Answer: The Post model instance matching the route ID

Route model binding automatically resolves the {post} parameter to a Post instance by finding it by its primary key. Throws 404 if not found.

Hint: Laravel resolves the model automatically.

What this challenge tests

Output Prediction in Laravel: route-binding, eloquent.

Related challenges