Route::get('/{model}/{name}{restrict}-{classid}{page}.html',function($model='',$name='',$restrict='',$classid=0,$page=1){//function})->where(['model'=>'android|ipad|iphone|mac|tv','name'=>'[\w]+','restrict'=>'-hot|-best|','classid'=>'[0-9]+','page'=>'-[0-9]+|']);
路由规则如上,因为restrict
参数可以为空,所以当url中不存在restrict
时,参数中就不会传递$restrict
了,结果导致第三个参数传递的是classid,有什么办法解决这个问题吗?
另外这个路由规则在老版本的laravel中是支持的,即使没有匹配到restrict
,参数列表也是传递$restrict
的。
Route::get('/{model}/{name}{restrict?}-{classid?}{page?}.html',function($model='',$name='',$restrict='',$classid=0,$page=1){//function})->where(['model'=>'android|ipad|iphone|mac|tv','name'=>'[\w]+','restrict'=>'-hot|-best|','classid'=>'[0-9]+','page'=>'-[0-9]+|']);
应该一个?就能解决问题吧