我希望为 SEO 目的为电子商务商店扁平化我的路线。
我想创建以下路线:
Route::get('/{country}', ['uses' => 'Store\ProductController@browseCountry']);
Route::get('/{category}, ['uses' => 'Store\ProductController@browseCategory']')
country
和category
必须是动态的。
我想知道类似以下的事情是否可行?以及实现的最佳方式。
// Route 1
Route::get('/{country}', ['uses' => 'Store\ProductController@browseCountry'])
->where('country', ProductCountry::select('slug')->get());
// Route 2
Route::get('/{category}', ['uses' => 'Store\ProductController@browseCategory'])
->where('category', ProductCategory::select('slug')->get());
示例路线:
/great-britain should be routed via Route 1
/china should be routed via Route 1
/widgets should fail route 1, but be routed via Route 2 because
widgets are not in the product_country table but are in
the product_category table
我知道我可以对可能的国家/地区的路线进行硬编码:
Route::get('/{country}', ['uses' => 'Store\ProductController@browse'])
->where('country', 'great-britain|china|japan|south-africa');
然而,这是笨拙和乏味的。我想从数据库中获取国家列表。