Named routes allow you to conveniently generate URLs or redirects for a specific route. You may specify a name for a route with the as
array key:
Route::get('user/profile', ['as' => 'profile', function()
{
//
}]);
You may also specify route names for controller actions:
Route::get('user/profile', [
'as' => 'profile', 'uses' => 'UserController@showProfile'
]);
Now, you may use the route's name when generating URLs or redirects:
$url = route('profile');
$redirect = redirect()->route('profile');
The currentRouteName
method returns the name of the route handling the current request:
$name = Route::currentRouteName();