laravel 路由命名

女人用丝袜征服了男人,男人用丝袜征服了银行。

 

定义:路由命名使得在生成重定向或者 URL 的时候更加方便地引用路由。您可以通过将 name 方法加到路由定义上来指定命名路由

使用:

Route::get('user/profile', function () {
    //
})->name('profile');

// 或者
Route::get('user/profile', 'UserController@showProfile')->name('profile');

 

好处:

为路由分配名称后,您可以在生成 URL 或重定向时,通过全局路由功能使用路由名称

// Generating URLs...
$url = route('profile');

// Generating Redirects...
return redirect()->route('profile');

 

posted @ 2022-10-19 08:59  方达达  阅读(6)  评论(0编辑  收藏  举报