简体   繁体   English

Laravel将url参数传递给控制器

[英]Laravel pass url parameter to controller

My current url I'm on is localhost/test/1 我当前使用的网址是localhost / test / 1

When I click on save button, it's going to call a rest service test/{id}/createNewTest . 当我单击保存按钮时,它将调用rest service test / {id} / createNewTest How do I get the {id} in the controller? 如何在控制器中获取{id}? Right now it's getting nothing. 现在什么也没有。

Routes 路线

Route::post('test/{id}/createNewTest', 'TestController@createNewTest');

Controller 调节器

public function createNewTest() {
   $id = Request::input('id');
}

the $id is suppose to be 1 here, but it's getting nothing $ id应该在这里是1,但是什么也没得到

Route parameters are passed into the controller via method parameters, not as request input: 路由参数通过方法参数而不是作为请求输入传递​​到控制器中:

public function createNewTest($id) {
    var_dump($id); // from method parameter, not Request::input()
}

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

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