Redirecting To Named Routes: Populating Parameters Via Eloquent Models

Populating Parameters Via Eloquent Models

// For a route with the following URI: profile/{id}

return redirect()->route('profile', [$user]);
/**
 * Get the value of the model's route key.
 *
 * @return mixed
 */
public function getRouteKey()
{
    return $this->slug;
}

If you would like to customize the value that is placed in the route parameter, you should override the getRouteKey method on your Eloquent model.

Related concepts

Redirecting To Named Routes: Populating Parameters Via Eloquent Models — Structure map

Clickable & Draggable!

Redirecting To Named Routes: Populating Parameters Via Eloquent Models — Related pages: