阅读(1992) (1)

命名路由

2016-02-24 15:51:36 更新

命名路由让你更方便于产生 URL 与重定向特定路由。您可以用 as 的数组键值指定名称给路由:

Route::get('user/profile', ['as' => 'profile', function()
{
    //
}]);

也可以为控制器动作指定路由名称:

Route::get('user/profile', [
    'as' => 'profile', 'uses' => 'UserController@showProfile'
]);

现在你可以使用路由名称产生 URL 或进行重定向:

$url = route('profile');
$redirect = redirect()->route('profile');
currentRouteName 方法会返回目前请求的路由名称:
$name = Route::currentRouteName();