Route model binding is used to automatically inject model instances into controllers, this will help to look code cleaner and more efficient.
// Define a route with implicit model binding
Route::get('post/{post}', [PostController::class, 'show']);
// Controller method with injected model
public function show(Post $post)
{
return view('post.show', compact('post'));
}
Defines a route with implicit model binding for the Route::get('post/{post}', [PostController::class, 'show']):{post} parameter.
Laravel automatically injects the Post model instance corresponding to the public function show(Post $post):{post} parameter into the show method.
You Might Also Like
Leverage Blade Control Structures Efficiently
Utilize Blade's control structures (@if, @foreach, @empty, etc.) effectively to minimize unnecessary...
How to Automatically Add User Info to Logs
**Log::withContext** in Laravel allows you to add extra information (like user details or other rele...