ilearn
ilearn

Reputation: 77

Laravel pass url parameter to controller

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

Upvotes: 1

Views: 1405

Answers (1)

patricus
patricus

Reputation: 62368

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()
}

Upvotes: 1

Related Questions