1
我正在開發電子商務應用程序。我需要根據url_key(url的一列)動態產品/類別url。Laravel動態路由
我試圖做這樣的事情:
if (Route::has('route.name')) {
// go where ever it is intended
}
else {
$productHelper = new ProductHelper();
$product = $productHelper->getProductByUrl($url_key);
if ($product)
return Redirect::to('product')->with('id', $product->id);
else {
$categoryHelper = new CategoryHelper();
$category = $categoryHelper->getCategoryByUrl($url_key);
if ($category)
return Redirect::route('category')->with('id', $category->id);
else
return View::make('static.page_not_found');
}
}
讓我們說我們有像URL:
/約 - 我們 /接觸我們
/索尼BRAVIA -b32(產品的url密鑰) /電視主導(一個類別的URL鍵)
現在我想檢查,如果一個url存在於「routes.ph p「文件,那麼它應該去那個網址(與數據一樣,如果提交表格)
否則,它會檢查url是否匹配產品或類別的url key並相應地移動。
Magento行爲的排序。我卡在if部分。
感謝mininoz,把動態路線放在最後解決了它。 – Ashutosh