orderBy('title')->get(); //remove Food Service from count /** @var \Illuminate\Database\Eloquent\Collection $gammes */ $gammes = $gammes->whereNotIn('slug','food-service'); $nb_gammes = $gammes->count(); return view('front.gammes.index', compact('gammes', 'nb_gammes')); } public function show(Gamme $gamme) { $gammes = collect([]); $dbGammes = Gamme::where('id', $gamme->id) ->with('childGammes')->get(); /** @var \App\Models\Gamme $dbGamme */ foreach ($dbGammes as $dbGamme) { $gammes->push($dbGamme->id); $dbGamme->childGammes->sortBy('title') ->map(function (Gamme $childGamme) use (&$gammes) { $gammes->push($childGamme->id); }); } $products = Product::whereIn('gamme_id', $gammes) ->where('is_published', 1) ->orderBy('name') ->get(); return view('front.gammes.show', compact('gamme', 'products')); } }