ldc-doux/app/Http/Controllers/GammesController.php

54 lines
1.6 KiB
PHP
Raw Normal View History

2021-12-22 17:32:05 +01:00
<?php
namespace App\Http\Controllers;
2022-05-12 16:03:40 +02:00
use App\Enums\Page;
2021-12-22 17:32:05 +01:00
use App\Models\Gamme;
use App\Models\Product;
2022-05-12 16:03:40 +02:00
use App\Models\SeoDatum;
2021-12-22 17:32:05 +01:00
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 */
2022-07-27 14:33:56 +02:00
$gammes = $gammes->whereNotIn('slug', 'food-service');
2021-12-22 17:32:05 +01:00
$nb_gammes = $gammes->count();
2022-05-12 16:03:40 +02:00
$page = Page::gammes();
2022-07-27 14:33:56 +02:00
$seoDatum = SeoDatum::where('page', $page)->first();
2022-05-12 16:03:40 +02:00
return view('front.gammes.index', compact('gammes', 'nb_gammes', 'seoDatum'));
2021-12-22 17:32:05 +01:00
}
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)
->where('is_published', 1)
2022-01-06 17:50:26 +01:00
->orderBy('name')
->get();
2021-12-22 17:32:05 +01:00
2022-05-12 16:03:40 +02:00
//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'));
2021-12-22 17:32:05 +01:00
}
}