我想创建这些网址结构。
1) domain.com/city/a-really-long-slug/optional-page
2) domain.com/city/optional-parameter/query-string-appended-string
如何修复第二条路线? 如果我提供可选参数但是如果我跳过可选参数则失败。
domain.com/city/query-appended-string
Fails! (Catches first route. Expects query-appended-string to be a slug)
domain.com/city/optional-parameter/query-appended-string
Works!
路线:
Route::group(['prefix' => '{city_name}', 'middleware' => 'MyMiddleware'], function(){
Route::get('{slug}/{page?}', array('as' => 'url-structure-1', 'uses' => 'HomeController@createProfile'))
->where(array(
'city_name' => '[a-zA-Z ]+',
'page' => '((?i)photos(?-i)|(?i)videos(?-i)|(?i)reviews(?-i)|(?i)more(?-i))',
'slug' => '[a-zA-Z-]+'
));
Route::get('{area?}/{query}-appended-string', array('as' => 'url-structure-2', function($city_name, $area="default", $query){
return func_get_args();
}))
->where(array(
'city' => '[a-zA-Z-]+',
'area' => '[a-zA-Z-]+',
'query', '[a-zA-Z-]+'
));
});