Route Model Binding: Implicit Binding

Route::get('api/users/{user}', function (App\User $user) {
    return $user->email;
});

Laravel automatically resolves Eloquent models defined in routes or controller actions whose type-hinted variable names match a route segment name.

Laravel automatically inject the model instance that has an ID matching the corresponding value from the request URI.

Customizing The Key Name

/**
 * Get the route key for the model.
 *
 * @return string
 */
public function getRouteKeyName()
{
    return 'slug';
}

Route Model Binding: Implicit Binding — Structure map

Clickable & Draggable!

Route Model Binding: Implicit Binding — Related pages: