繁体   English   中英

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

[英]How to pass route parameters to webcontroller in Laravel?

我从Laravel 手册中读到我能做到这一点:

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的新手,所以我不知道搜索的关键字。 请帮忙。 谢谢。

您只需在控制器中编写即可

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM