128 lines
4.1 KiB
PHP
128 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
use App\Enums\Advices\AdviceTypeEnum;
|
|
use App\Enums\ExpertiseProducts\ExpertiseProductPageEnum;
|
|
use App\Enums\Products\ProductSpeciesEnum;
|
|
use App\Enums\StaticPageType;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Advice;
|
|
use App\Models\ExpertiseProduct;
|
|
use App\Models\Product;
|
|
use App\Models\StaticPage;
|
|
|
|
class ExpertiseController extends Controller
|
|
{
|
|
/**
|
|
* Show expertise page (duck).
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*
|
|
*/
|
|
public function canard(): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('fo.pages.expertise.canard', $this->getExpertiseData(
|
|
StaticPageType::expertise_duck,
|
|
ExpertiseProductPageEnum::duck,
|
|
ProductSpeciesEnum::canard
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Show expertise page (turkey).
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function dinde(): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('fo.pages.expertise.dinde', $this->getExpertiseData(
|
|
StaticPageType::expertise_turkey,
|
|
ExpertiseProductPageEnum::turkey,
|
|
ProductSpeciesEnum::dinde
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Show expertise page (rabbit).
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function lapin(): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('fo.pages.expertise.lapin', $this->getExpertiseData(
|
|
StaticPageType::expertise_rabbit,
|
|
ExpertiseProductPageEnum::rabbit,
|
|
ProductSpeciesEnum::lapin
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Show expertise page (guineafowl).
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function pintade(): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('fo.pages.expertise.pintade', $this->getExpertiseData(
|
|
StaticPageType::expertise_guineafowl,
|
|
ExpertiseProductPageEnum::guineafowl,
|
|
ProductSpeciesEnum::pintade
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Show expertise page (chicken).
|
|
*
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function poulet(): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('fo.pages.expertise.poulet', $this->getExpertiseData(
|
|
StaticPageType::expertise_chicken,
|
|
ExpertiseProductPageEnum::chicken,
|
|
ProductSpeciesEnum::poulet
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Get all expertise data needed.
|
|
*
|
|
* @param \App\Enums\StaticPageType $enumStaticPageType
|
|
* @param \App\Enums\ExpertiseProducts\ExpertiseProductPageEnum $enumExpertiseProductPage
|
|
* @param \App\Enums\Products\ProductSpeciesEnum $enumProductSpecies
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getExpertiseData(
|
|
StaticPageType $enumStaticPageType,
|
|
ExpertiseProductPageEnum $enumExpertiseProductPage,
|
|
ProductSpeciesEnum $enumProductSpecies
|
|
): array {
|
|
/** @var \App\Models\StaticPage $staticPageModel */
|
|
$staticPageModel = StaticPage::query()->where('type', $enumStaticPageType->value())->first();
|
|
|
|
/** @var \App\Models\ExpertiseProduct $productVipModels */
|
|
$productVipModels = ExpertiseProduct::query()->where('page', $enumExpertiseProductPage->value())->get();
|
|
|
|
/** @var \App\Models\Product $productModels */
|
|
$productModels = Product::query()->where('status', true)
|
|
->where('species', $enumProductSpecies->value())
|
|
->inRandomOrder()
|
|
->limit(3)
|
|
->with('subrange.range')
|
|
->get();
|
|
|
|
/** @var \App\Models\Recipe $recipeModels */
|
|
$recipeModels = Advice::query()->whereHas('products', function ($query) use ($enumProductSpecies) {
|
|
return $query->where('species', $enumProductSpecies->value());
|
|
})->where('type', AdviceTypeEnum::recipes)->limit(3)->get();
|
|
|
|
return [
|
|
'staticPageModel' => $staticPageModel,
|
|
'productVipModels' => $productVipModels,
|
|
'productModels' => $productModels,
|
|
'recipeModels' => $recipeModels
|
|
];
|
|
}
|
|
}
|