命名路由

2018-02-24 15:51 更新

命名路由讓你更方便于產(chǎn)生 URL 與重定向特定路由。您可以用 as 的數(shù)組鍵值指定名稱給路由:

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

也可以為控制器動作指定路由名稱:

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

現(xiàn)在你可以使用路由名稱產(chǎn)生 URL 或進(jìn)行重定向:

$url = route('profile');
$redirect = redirect()->route('profile');
currentRouteName 方法會返回目前請求的路由名稱:
$name = Route::currentRouteName();
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號