Laravel 5.5 路由中的可选参数不起作用
Laravel 5.5 optional parameter in routing is not working
路线:
$router->get('vehicle/{year}/{make}/{model}/{rating?}','VehicleController@vehicle');
控制器动作
public function vehicle($year, $make, $model, $rating = false)
{
// Implementation
}
URL
http://localhost:8080/vehicle/2010/Wapal/S2
错误
(1/1) NotFoundHttpException
事情很明显了,肯定是laravel核心的bug?为什么会出现此错误?
试试看,应该有用
$router->get('vehicle/{year}/{make}/{model}[/{rating}]','VehicleController@vehicle');
终于设法让它与多个可选参数一起工作,希望它能有所帮助。
适用于 Lumen 5.6。
示例:
$app->get(
'vehicle[/{optional_year}[/{optional_make}[/{optional_model[/{optional_rating}]]]]',
['middleware' => 'auth' , 'uses' => 'VehicleController@vehicle']
);
如果您不使用任何中间件,类似的东西应该可以工作:
$app->get(
'vehicle[/{optional_year}[/{optional_make}[/{optional_model[/{optional_rating}]]]]',
'VehicleController@vehicle'
);
路线:
$router->get('vehicle/{year}/{make}/{model}/{rating?}','VehicleController@vehicle');
控制器动作
public function vehicle($year, $make, $model, $rating = false)
{
// Implementation
}
URL http://localhost:8080/vehicle/2010/Wapal/S2
错误
(1/1) NotFoundHttpException
事情很明显了,肯定是laravel核心的bug?为什么会出现此错误?
试试看,应该有用
$router->get('vehicle/{year}/{make}/{model}[/{rating}]','VehicleController@vehicle');
终于设法让它与多个可选参数一起工作,希望它能有所帮助。 适用于 Lumen 5.6。
示例:
$app->get(
'vehicle[/{optional_year}[/{optional_make}[/{optional_model[/{optional_rating}]]]]',
['middleware' => 'auth' , 'uses' => 'VehicleController@vehicle']
);
如果您不使用任何中间件,类似的东西应该可以工作:
$app->get(
'vehicle[/{optional_year}[/{optional_make}[/{optional_model[/{optional_rating}]]]]',
'VehicleController@vehicle'
);