ldc-doux/app/Http/Controllers/GammesController.php
Olivier Legat fee051a7de Squashed commit of the following:
commit c87deb1d185b5cce65e417fde124a2691e268355
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Wed Apr 13 10:58:17 2022 +0200

    Fix bug when product not published but display

commit 93de503ce91b3f36251f00340344046aa8218b36
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Wed Apr 13 10:57:11 2022 +0200

    Product in BO - Gamme required setting

commit b1da45a5fba0c4a8aacbe10d06ada6ef93e748a0
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 17:45:21 2022 +0200

    Header - Size of search picture fix bug in IOS

commit 590772a2483be51dc9e89aa44822e20eb414dca6
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 10:18:46 2022 +0200

    Slide - Remove title and text display in BO

commit 08daf95799ab591167f33dfad6a6fec37aa4090a
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 10:13:41 2022 +0200

    form Contact : add drom list if france choose

commit f5ba031076bbb51655eaa2451bce06902191c116
Author: Sebastien Hattry <sebastien.hattry@ldc.fr>
Date:   Tue Apr 12 09:59:16 2022 +0200

    Add story line Svg if needed
2022-04-26 09:42:40 +02:00

40 lines
1.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Gamme;
use App\Models\Product;
class GammesController extends Controller
{
public function index()
{
$gammes = Gamme::whereNull('parent_gamme_id')->orderBy('title')->get();
$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'));
}
}