Question

I have this route with an optional parameters:

Route::get('{id}/results/subject/{subject_id}/{step_id?}', array('as' =>'test', 'uses' => '\Controllers\TestController@Show'));

and I got this in my TestController

function Show($id, $subject_id, $step_id){
//Some stuff
}

I want to attribute a default value to my optional step_id parameter just like here. If I don't attribute a default value, I got a missing parameter error for my controller.

I've tried

Route::get('{id}/results/subject/{subject_id}/{step_id?}', array('as' =>'test', 'uses' => '\Controllers\TestController@Show', function($step_id = '3'){return $step_id});

and

Route::get('{id}/results/subject/{subject_id}/{step_id?}',function($step_id = '3'){return $step_id}, array('as' =>'test', 'uses' => '\Controllers\TestController@Show'));

but both are not working.

Was it helpful?

Solution

Just set the default in your function like so.

function ShowFactorRat($id, $subject_id, $step_id="default value here"){
//Some stuff
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top