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(); } return view ('product', compact('product')); } public function allProducts(Request $request) { //do better $filter = $request->query('filter'); $filtertag = $request->query('tag'); if (!empty($filter)) { $products = Product::where('status', 1) ->where('name', 'like', '%'.$filter.'%') ->paginate(12); } elseif (!empty($filtertag)) { $products = Product::where('status', 1) ->whereHas('tags', function($q) use($filtertag) { $q->where('slug', '=', Str::slug($filtertag)); }) ->paginate(12); } else { $products = Product::where('status', 1)->paginate(12); } return view ('search', compact('products', 'filter', 'filtertag')); } }