2021-12-22 17:32:05 +01:00
|
|
|
<?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();
|
2022-05-10 12:28:00 +02:00
|
|
|
//remove Food Service from count
|
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection $gammes */
|
|
|
|
|
$gammes = $gammes->whereNotIn('slug','food-service');
|
2021-12-22 17:32:05 +01:00
|
|
|
$nb_gammes = $gammes->count();
|
|
|
|
|
|
|
|
|
|
return view('front.gammes.index', compact('gammes', 'nb_gammes'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(Gamme $gamme)
|
|
|
|
|
{
|
2022-01-06 17:50:26 +01:00
|
|
|
$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)
|
2022-04-26 09:42:40 +02:00
|
|
|
->where('is_published', 1)
|
2022-01-06 17:50:26 +01:00
|
|
|
->orderBy('name')
|
|
|
|
|
->get();
|
2021-12-22 17:32:05 +01:00
|
|
|
|
|
|
|
|
return view('front.gammes.show', compact('gamme', 'products'));
|
|
|
|
|
}
|
|
|
|
|
}
|