【发布时间】:2016-12-03 17:00:06
【问题描述】:
有一个包含三个过滤器(位置、类别、事件类型)的提供商列表,我需要在路由中连接过滤器以使 url 更友好,就像 ej.:mysite.com/filter/location/科尔多瓦/事件类型/除草/类别/旅行 这些过滤器不是必需的,所以我可以只过滤位置,或位置和类别,事件类型和类别等。现在我的问题是,¿我可以在 laravel 5.2 中这样做吗?
我之前这样做是这样的:
Route::get('/filtro/localidad/{localidad?}', [
'uses' => 'ProviderController@filterLocation',
'as' => 'site_filter_location_path'
]);
Route::get('/filtro/tipo_evento/{event_type?}', [
'uses' => 'ProviderController@filterEventType',
'as' => 'site_filter_event_type_path'
]);
Route::get('/filtro/rubro/{caption?}', [
'uses' => 'ProviderController@filterCaption',
'as' => 'site_filter_caption_path'
]);
我需要这样的东西(它给我一个错误,我只放了一个或两个参数)
Route::get('/filtro/location/{localidad?}/event_type/{event_type?}/caption/{caption?}', [
'uses' => 'ProviderController@filter',
'as' => 'site_filter_path'
]);
假设我按位置和类别搜索,那么 url 将是这样的:mysite.com/location/cordoba/event_type//caption/travel 这会生成一个错误的 url,这给了我错误,那我该怎么办这个?
【问题讨论】:
-
除了这是否可破解之外,您可能需要考虑到虽然理论上(根据 RFC)在 URL 中使用双斜杠是可以接受的,但您永远不知道某些浏览器或链接处理器是什么就像谷歌一样。当它认为这是一个糟糕的 url 时,我会选择 laravel。
-
感谢您的回答,现在对于 laravel 来说,这是一个错误的 url,所以我不能用双斜杠创建一个 url。
标签: php laravel routing routes