orderBy('title')->get(); // remove Food Service from count /** @var \Illuminate\Database\Eloquent\Collection $gammes */ $gammes = $gammes->whereNotIn('slug', 'food-service'); $nb_gammes = $gammes->count(); $page = Page::gammes(); $seoDatum = SeoDatum::where('page', $page)->first(); return view('front.gammes.index', compact('gammes', 'nb_gammes', 'seoDatum')); } 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(); // make ghost seoDatum from the gamme $seoDatum = new SeoDatum(); $seoDatum->title = $gamme->title; $seoDatum->description = $gamme->text; return view('front.gammes.show', compact('gamme', 'products', 'seoDatum')); } }