【发布时间】:2015-09-22 08:09:09
【问题描述】:
我需要创建一个包含一些固定和动态部分的路线。基本上我需要灵活处理 url 的第二段。如果 url 以 'products/test....' 开头,则路由必须转到 PageController,所有其他以 'products/....' 开头的路由都必须转到 ProductController。
// Something like this:
Route::any('products/".starts_with($slug, 'test'), [
'uses' => 'PageController@show'
])->where('slug', '(.*)?');
Route::get('products/{slug}', [
'uses' => 'ProductController@show'
]);
这在 Laravel 5 中可行吗?
【问题讨论】:
-
那么这条路线有什么问题?
-
'starts_with($slug, 'test')' 部分。不工作,以我试图实现的目标为例。
-
你能在这里展示你试图实现的示例网址吗?
-
你可以试试
Route::any('products/test/{slug}', ["usage"=>"PageController@show"])。