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) { $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); } $search_title = 'Recherche : ' .$filter; return view('search', compact('products', 'search_title', 'filter')); } public function tagFiltered(Request $request, $tag_slug) { $products = Product::where('status', 1) ->whereHas('tags', function($q) use($tag_slug) { $q->where('slug', '=', $tag_slug); }) ->paginate(12); $tag = Tag::where('slug', $tag_slug)->first(); $search_title = $tag->label; return view('search', compact('products', 'search_title', 'tag')); } }