first(); $products = Product::where('range_id', $range->id)->where('status',1)->paginate(9); //find promo within range $offres = Product::where('range_id', $range->id)->where('status',1)->has('promotions')->with('promotions')->get(); return view('range', compact('range','products','offres')); } public function product(Request $request, $product_slug) { $product = Product::where('slug', $product_slug)->first(); $product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type); if ($product->additionnalProductInfo === null) { //n'existe pas on renseigne un vide $product_type = $product->product_type; $modelClass = 'App\Models\\' . ucfirst($product_type); $product->$product_type = new $modelClass(); } $associated = $product->products; return view ('product', compact('product', 'associated')); } public function allProducts(Request $request) { //do better $filter = $request->query('filter'); if (!empty($filter)) { $products = Product::where('status', 1) ->where('name', 'like', '%'.$filter.'%') ->paginate(12); } else { $products = Product::where('status', 1)->paginate(12); } return view('search', compact('products', 'filter')); } }