orderBy('order', 'ASC')->get(); $rangesNames = Ranges::select('name', 'slug')->where('status', 1)->get(); $meatTypes = MeatTypes::select('name', 'slug')->where('status', 1)->get(); $ct = ConsumptionTimes::select('name', 'slug')->where('status', 1)->get(); // Gamme à afficher sur la première page $ranges = Ranges::where('status', 1)->get(); return view('front.products.index', compact('productsSlides', 'rangesNames', 'ranges', 'meatTypes', 'ct')); } public function filter($slug) { // On récupère les mêmes données qu'au dessus pour l'affichage $productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get(); $rangesNames = Ranges::select('name', 'slug')->where('status', 1)->get(); $meatTypes = MeatTypes::select('name', 'slug')->where('status', 1)->get(); $ct = ConsumptionTimes::select('name', 'slug')->where('status', 1)->get(); $type = explode('/', Route::getCurrentRoute()->uri)[1]; $productsList = null; $title = null; $gamme = false; $typeViande = false; $momentConso = false; switch ($type) { case 'gamme': $range = Ranges::where([['slug', $slug], ['status', 1]])->first(); if (!$range) abort(404); $productsList = $range->products; $title = $range->name; $gamme = true; break; case 'type-viande': $meatType = MeatTypes::where([['slug', $slug], ['status', 1]])->first(); if (!$meatType) abort(404); $productsList = $meatType->products; $title = $meatType->name; $typeViande = true; break; case 'moment-conso': $consumptionTime = ConsumptionTimes::where([['slug', $slug], ['status', 1]])->first(); if (!$ct) abort(404); $productsList = $consumptionTime->products; $title = $consumptionTime->name; $momentConso = true; break; default: abort(404); break; } return view('front.products.index', compact('productsList', 'productsSlides', 'rangesNames', 'meatTypes', 'ct', 'title', 'gamme', 'typeViande', 'momentConso')); } public function departaimants() { $productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get(); $rangesNames = Ranges::select('name', 'slug')->where('status', 1)->get(); $meatTypes = MeatTypes::select('name', 'slug')->where('status', 1)->get(); $ct = ConsumptionTimes::select('name', 'slug')->where('status', 1)->get(); $productsList = Products::where([['status', 1], ['departaimants', 1]])->get(); $departaimants = true; $title = "Départ'Aimants"; return view('front.products.index', compact('productsList', 'departaimants', 'productsSlides', 'rangesNames', 'meatTypes', 'ct', 'title')); } public function show($slug) { $product = Products::where('slug', $slug)->first(); $recipes1 = $product->recipes_associated_1()->get(); $recipes2 = $product->recipes_associated_2()->get(); $ids = []; foreach ($recipes1 as $r) $ids[] = $r->id; foreach ($recipes2 as $r) $ids[] = $r->id; $ids = array_unique($ids); $recipes = Recipes::whereIn('id', $ids)->get(); return view('front.products.product', compact('product', 'recipes')); } public function addToCart($slug) { $product = Products::where('slug', $slug)->first(); $product->customers()->attach(Auth::guard('customer')->user()->id); return "OK"; } public function removeFromCart($slug) { $product = Products::where('slug', $slug)->first(); $product->customers()->dettach(Auth::guard('customer')->user()->id); return "OK"; } }