SEO の目的で、e コマース ストアのルートを平坦化しようとしています。
次のルートを作成したいと思います。
Route::get('/{country}', ['uses' => 'Store\ProductController@browseCountry']);
Route::get('/{category}, ['uses' => 'Store\ProductController@browseCategory']')
country
andは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');
しかし、これは不器用で面倒です。データベースから国のリストを取得したいと思います。