Route model binding lets Laravel resolve a route parameter into an Eloquent model.
Example:
Route::get('/products/{product}', [ProductController::class, 'show']);
Controller:
public function show(Product $product)
{
return $product;
}
Instead of manually doing Product::findOrFail($id), Laravel can resolve the model.
Scenario:
For /products/25, Laravel can retrieve Product 25 and automatically produce a not-found response when appropriate.
A developer should understand custom keys as well, such as binding by slug rather than numeric ID. This is useful for SEO-friendly URLs.
Interview follow-up:
Explain the difference between implicit and explicit binding and how scoped bindings work for nested resources.
0 comments:
Post a Comment
Thanks