[英]Laravel 5.1: Controller use variable from method [Get]
I have code in route.php 我在route.php中有代码
Route::get('website/{post}/{comment}', ['uses'=>'MainController@add']);
In file MainController: 在文件MainController中:
public function add(Requests $request){
$data = $request->all();
echo $data['post'];
echo $data['comment'];
}
Can i do like this? 我可以这样吗? If i can, help me fix it.
如果可以的话,请帮我解决。
Thank you! 谢谢!
See the documentation on controllers . 请参阅有关控制器的文档。
Your controller code should look like this: 您的控制器代码应如下所示:
public function add($post, $comment){
echo $post;
echo $comment;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.