39 lines
1 KiB
PHP
39 lines
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)
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return view('front.gammes.show', compact('gamme', 'products'));
|
|
}
|
|
}
|