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
|
|
|
|
|
{
|
2022-08-29 17:23:10 +02:00
|
|
|
/**
|
|
|
|
|
* Show the Gammes view.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2021-12-22 17:32:05 +01:00
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
$gammes = Gamme::whereNull('parent_gamme_id')->orderBy('title')->get();
|
2022-08-29 17:23:10 +02:00
|
|
|
// Remove Food Service from count.
|
2022-05-10 12:28:00 +02:00
|
|
|
/** @var \Illuminate\Database\Eloquent\Collection $gammes */
|
2022-08-11 12:34:27 +02:00
|
|
|
$gammes = $gammes->whereNotIn('slug', 'food-service');
|
2021-12-22 17:32:05 +01:00
|
|
|
$nb_gammes = $gammes->count();
|
|
|
|
|
|
2022-08-11 12:34:27 +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
|
|
|
}
|
|
|
|
|
|
2022-08-29 17:23:10 +02:00
|
|
|
/**
|
|
|
|
|
* Show one Gamme
|
|
|
|
|
*
|
|
|
|
|
* @param Gamme $gamme
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2021-12-22 17:32:05 +01:00
|
|
|
public function show(Gamme $gamme)
|
|
|
|
|
{
|
2022-08-11 12:34:27 +02:00
|
|
|
$gammes = collect([]);
|
2022-01-06 17:50:26 +01:00
|
|
|
$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
|
|
|
|
2022-08-29 17:23:10 +02:00
|
|
|
// Make ghost seoDatum from the gamme.
|
2022-08-11 12:34:27 +02:00
|
|
|
$seoDatum = new SeoDatum();
|
|
|
|
|
$seoDatum->title = $gamme->title;
|
2022-05-12 16:03:40 +02:00
|
|
|
$seoDatum->description = $gamme->text;
|
|
|
|
|
|
|
|
|
|
return view('front.gammes.show', compact('gamme', 'products', 'seoDatum'));
|
2021-12-22 17:32:05 +01:00
|
|
|
}
|
|
|
|
|
}
|