ldc-legaulois/app/Http/Controllers/Fo/BreedingController.php

107 lines
3.5 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Http\Controllers\Fo;
use App\Enums\StaticPageType;
use App\Http\Controllers\Controller;
use App\Lib\Helpers\CollectionHelper;
2026-03-31 11:49:27 +02:00
use App\Models\CategoryApproach;
use App\Models\NewsBreeding;
2024-12-05 10:51:19 +01:00
use App\Models\OcbBreeder;
use App\Models\SectionApproach;
use App\Models\StaticPage;
2026-09-25 16:25:31 +02:00
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Builder;
class BreedingController extends Controller
{
/**
* Display the given breeding page.
*/
2026-09-25 16:25:31 +02:00
public function breedingPage(StaticPage $staticPage): View
{
$newsBreedingModels = NewsBreeding::getPublishedOrderedForType($staticPage);
2026-09-25 16:25:31 +02:00
return view('fo.pages.breeding.show', [
'staticPageModel' => $staticPage,
'newsBreedingModels' => $newsBreedingModels,
]);
}
2024-12-05 10:51:19 +01:00
/**
* Display the given breeding page.
*/
2026-09-25 16:25:31 +02:00
public function ocbBreederPage(): View
2024-12-05 10:51:19 +01:00
{
2026-05-06 17:11:13 +02:00
$ocbBreederModels = OcbBreeder::getOcbBreederCards();
$staticPage = StaticPage::query()->where('type', StaticPageType::ouiCBon)->first();
$categoryApproachModels = CategoryApproach::all();
2026-05-13 15:02:14 +02:00
$sections = SectionApproach::query()
2026-05-07 15:51:26 +02:00
->with('category')
->where('page_id', $staticPage->id)
->get()
2026-09-25 16:25:31 +02:00
->groupBy(fn ($section) => $section->category?->name);
2024-12-05 10:51:19 +01:00
return view('fo.pages.breeding.oui-c-est-bon', [
2026-09-25 16:25:31 +02:00
'ocbBreederModels' => $ocbBreederModels,
'staticPageModel' => $staticPage,
'categoryApproachModels' => $categoryApproachModels,
2026-09-25 16:25:31 +02:00
'sections' => $sections,
2024-12-05 10:51:19 +01:00
]);
}
/**
* Display the given breeding article.
*/
2026-09-25 16:25:31 +02:00
public function breedingArticle(StaticPage $staticPage, NewsBreeding $newsBreeding): View
{
$asideNewsModels = NewsBreeding::query()
->whereHas('staticpage', function (Builder $query) use ($staticPage) {
$query->where('type', $staticPage->type);
})
->where('published', true)
2024-10-21 16:57:20 +02:00
->whereNot('id', $newsBreeding->getKey())
->inRandomOrder()
->limit(2)
->get();
return view('fo.pages.breeding.article', [
'staticPageModel' => $staticPage,
'newsBreedingModel' => $newsBreeding,
2026-09-25 16:25:31 +02:00
'asideNewsModels' => $asideNewsModels,
]);
}
2026-05-07 15:51:26 +02:00
/**
* Display the given breeding page.
*/
2026-09-25 16:25:31 +02:00
public function exitOutsidePage(): View
{
2026-03-03 17:22:33 +01:00
$staticPage = StaticPage::query()->where('type', StaticPageType::exitOutside)->first();
$sliderImages = CollectionHelper::mapSlidesToFields($staticPage->data);
2026-03-31 11:49:27 +02:00
$categoryApproachModels = CategoryApproach::all();
2026-05-13 15:02:14 +02:00
$sections = SectionApproach::query()
2026-05-07 15:51:26 +02:00
->with('category')
->where('page_id', $staticPage->id)
->get()
2026-09-25 16:25:31 +02:00
->groupBy(fn ($section) => $section->category?->name);
2026-03-03 17:22:33 +01:00
return view('fo.pages.breeding.sortant-a-l-exterieur', [
2026-09-25 16:25:31 +02:00
'staticPageModel' => $staticPage,
'sliderImages' => $sliderImages,
'categoryApproachModels' => $categoryApproachModels,
2026-09-25 16:25:31 +02:00
'sections' => $sections,
]);
}
2026-04-23 10:59:01 +02:00
/**
* Display our farms page.
*/
2026-09-25 16:25:31 +02:00
public function ourFarmsPage(): View
{
$staticPage = StaticPage::query()->where('type', StaticPageType::ourFarms)->first();
2026-09-25 16:25:31 +02:00
return view('fo.pages.breeding.index', ['staticPageModel' => $staticPage]);
}
}