如何将路由参数传递给Laravel中的webcontroller?

时间:2016-07-09 05:51:50

标签: php laravel routing

我已经从Laravel manual读到我可以这样做:

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

我还读到你可以将路由直接传递给webcontroller:

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

但我无法找到的是如何将变量id传递给webcontroller。

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

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

1 个答案:

答案 0 :(得分:3)

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

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