Php Laravel将url参数传递给控制器

Php Laravel将url参数传递给控制器,php,laravel,laravel-4,Php,Laravel,Laravel 4,我当前所在的url是localhost/test/1 当我单击save按钮时,它将调用rest服务测试/{id}/createNewTest。如何在控制器中获取{id}?现在一无所获 路线 控制器 此处假定$id为1,但它什么也得不到路由参数通过方法参数传递到控制器,而不是作为请求输入: public function createNewTest($id) { var_dump($id); // from method parameter, not Request::input() }

我当前所在的url是localhost/test/1

当我单击save按钮时,它将调用rest服务测试/{id}/createNewTest。如何在控制器中获取{id}?现在一无所获

路线 控制器
此处假定$id为1,但它什么也得不到

路由参数通过方法参数传递到控制器,而不是作为请求输入:

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

@我知道你的路线定义看起来不错。你确定你没有发布到
test/0/createNewTest
?嗯。在数据库中,它发布为0,但当我将$id转储出去时,它显示为{id}。另外,RESTURL被传递给$.ajax(类型:'POST',url:test/{id}/createNewTest,数据:postParam)。也许ajax有问题?@i了解生成该ajax请求的任何代码都没有用id值替换{id}。这需要修正。
public function createNewTest() {
   $id = Request::input('id');
}
public function createNewTest($id) {
    var_dump($id); // from method parameter, not Request::input()
}