I would like to know how to add an optional route parameter for a controller method:
Currently I have a route, shown below:
Route::get('devices/{code}/{area}','HomeController@getDevices');
and a controller method:
public function getDevices($code=NULL,$area) {...}
My get request will look like:
/devices/A/ABC
It's working fine, but I want the {code} parameter to be optional so that I can get data in different ways:
/devices//ABC or
/devices/ABC
I've tried the following, but all failed with NotFoundHttpException
Route::get('devices/{code?}/{area}','HomeController@getDevices');
Route::get('devices/(:any?)/{area}','HomeController@getDevices');
Thanks for your help.