0
我想訂購產品的價格與一個鏈接從低到高和其他高到低, 但我點擊「由低到高」或「從高到低」的順序沒有改變,它保持在同一頁面上,但url正在改變。發行按照價格在laravel訂購產品
這是在控制器中的功能:
public function products(Request $request, $category_url, $sort= 'ASC')
{
Product::getProducts($category_url, self:: $data);
if ($category1 = Categorie::where('url', '=', $category_url)->first()) {
$products = Product::where('categorie_id', $category1->getAttribute('id'))->orderBy('price', $sort)->get();
return view('content.products', self::$data , compact('products', 'sort'));
}
}
這是路由:
Route::get('shop/{category_url}/sorting-{sort?}', '[email protected]');
那些是從視圖的鏈接,該視圖是content.products
<a href=" {{ url('shop/'.$category['url'].'/sorting-asc')}}" style="color:black"> High to low</a> |
<a href=" {{ url('shop/'.$category['url'].'/sorting-desc')}}" style="color:black">Low to high</a>
該型號:
class Product extends Model {
static public function getProducts($category_url, &$data){
$data['products']=$data['category']=[];
if ($category=Categorie::where('url','=', $category_url)->first()){
$category= $category->toArray();
$data['category']=$category;
$data['title']=$data['title']. ' | ' . $category['title'];
if ($products=Categorie::find($category['id'])->products){
$data['products']= $products->toArray();
}
}
}
改變了這個https://pastebin.com/57vFCA3r但仍然順序沒有變化,產品保持相同的順序 –
上@ RO.IT什麼是你的視圖代碼? – ShahinSorkh
這裏https://pastebin.com/KT5KijBi –