如何将路由参数传递给拉拉维尔中的网络控制器



我从Laravel手册中读到我可以这样做:

Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});

我还读到您可以将路由直接传递给网络控制器:

Route::get('user', 'WebController@profile');

但是我找不到的是如何将变量 id 传递给网络控制器。

Route::get('user/{id}', 'WebController@profile'); 
// how so that the function profile at WebController receive the id?

我觉得这是一件非常基本的事情,但我找不到它。我是Laravel的新手,所以我不知道搜索这个的关键字。请帮忙。谢谢。

您可以简单地在控制器中写入

public function profile($id){
   //Here $id is having the value that you were passing
}

最新更新