1

My current url I'm on is localhost/test/1

When I click on save button, it's going to call a rest service test/{id}/createNewTest. How do I get the {id} in the controller? 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

1 Answer 1

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()
}
Sign up to request clarification or add additional context in comments.

3 Comments

@ilearn Your route definition looks fine. Are you sure you didn't POST to test/0/createNewTest?
hmm. In the database, it's posted as 0, but when I dumped $id out, it's show {id}. Also, the rest url is passed to an $.ajax(type: 'POST', url: test/{id}/createNewTest, data: postParam). Maybe there's something wrong in the ajax?
@ilearn whatever code you have generating that ajax request is not replacing {id} with the id value. That needs to be fixed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.