2016-07-09 71 views
1

我从Laravel manual读,我可以这样做:如何将路由参数传递给Laravel中的webcontroller?

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

我也看到了,你可以直接传递路线webcontroller:

Route::get('user', '[email protected]'); 

但我可以” t find是如何将变量id传递给webcontroller的。

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

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

回答

3

您只需将控制器

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

哦,内写了,这么简单?男人,我一直在尝试使用'Route :: get('user/{id}','WebController @ profile($ id)')几个小时;'......非常感谢你!我会尽快接受这一点。 –

相关问题