2017-07-17 76 views
1

我想訂購產品的價格與一個鏈接從低到高,另一個由高到低, ,我得到這個錯誤:「應用程序\ Http \ Controllers \ ShopController ::產品缺少參數3 ()「當我打開'content.products'時,頁面。 這是在控制器中的功能:缺失的參數3

public function products(Request $request,$category_url,$sort){ 
    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> 
+0

您是否有其他路線以「shop」開頭? – aynber

回答

0

變化

public function products(Request $request,$category_url,$sort){

public function products(Request $request,$category_url,$sort = 'ASC'){

這給出了一個默認值到最後一個參數。並確保還

Route::get('shop/{category_url}/sorting-{sort}','[email protected]');

Route::get('shop/{category_url}/sorting-{sort?}','[email protected]');

使最後一個參數形成url可選。

+0

謝謝,現在它不顯示錯誤,但點擊從低到高或從高到低,產品順序不變 –