144 lines
5 KiB
PHP
144 lines
5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\GeneralConfigType;
|
|
use App\Models\BalancedMenus;
|
|
use App\Models\ConsumptionTimes;
|
|
use App\Models\ProductSliderPictures;
|
|
use App\Models\MeatTypes;
|
|
use App\Models\Products;
|
|
use App\Models\Range;
|
|
use App\Models\Recipes;
|
|
use App\Models\SubRange;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class ProductsController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get();
|
|
$meatTypes = MeatTypes::select('name', 'slug')->where('status', 1)->get();
|
|
$ct = ConsumptionTimes::select('name', 'slug')->where('status', 1)->get();
|
|
$ranges = Range::where('status', 1)->with('products:id,range_id,picture')->get();
|
|
|
|
return view('front.products.index', compact('productsSlides', 'ranges', 'meatTypes', 'ct'));
|
|
}
|
|
|
|
public function filter(Model $model, SubRange $subrange = null)
|
|
{
|
|
// On récupère les mêmes données qu'au dessus pour l'affichage
|
|
$productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get();
|
|
$ranges = Range::where('status', 1)->get();
|
|
$meatTypes = MeatTypes::select('name', 'slug')->where('status', 1)->get();
|
|
$ct = ConsumptionTimes::select('name', 'slug')->where('status', 1)->get();
|
|
|
|
$type = explode('/', Route::getCurrentRoute()->uri)[1];
|
|
$productsList = null;
|
|
$title = null;
|
|
$gamme = false;
|
|
$typeViande = false;
|
|
$momentConso = false;
|
|
$subranges = false;
|
|
|
|
switch ($type) {
|
|
case 'gamme':
|
|
/** @var \App\Models\Range */
|
|
$gamme = $model;
|
|
$subranges = $gamme->subranges()->orderBy('order')->get();
|
|
if ($subrange) {
|
|
$title = $gamme->name;
|
|
$productsList = $gamme->products()
|
|
->where('status', true)
|
|
->where('sub_range_id', $subrange->id)
|
|
->orderBy('order')
|
|
->get();
|
|
} else {
|
|
$productsList = $gamme->products->where('status', 1)->sortBy('order');
|
|
$title = $gamme->name;
|
|
}
|
|
break;
|
|
case 'type-viande':
|
|
/** @var \App\Models\MeatTypes */
|
|
$meatType = $model;
|
|
$productsList = $meatType->products->where('status', 1)->sortBy('order');
|
|
$title = $meatType->name;
|
|
$typeViande = true;
|
|
break;
|
|
case 'moment-consommations':
|
|
/** @var \App\Models\ConsumptionTimes */
|
|
$consumptionTime = $model;
|
|
$productsList = $consumptionTime->products->where('status', 1)->sortBy('order');
|
|
$title = $consumptionTime->name;
|
|
$momentConso = true;
|
|
break;
|
|
default:
|
|
abort(404);
|
|
break;
|
|
}
|
|
|
|
return view('front.products.index', compact(
|
|
'productsList',
|
|
'productsSlides',
|
|
'ranges',
|
|
'subranges',
|
|
'subrange',
|
|
'meatTypes',
|
|
'ct',
|
|
'title',
|
|
'gamme',
|
|
'typeViande',
|
|
'momentConso'
|
|
));
|
|
}
|
|
|
|
public function departaimants()
|
|
{
|
|
$productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get();
|
|
$ranges = Range::where('status', 1)->get();
|
|
$meatTypes = MeatTypes::select('name', 'slug')->where('status', 1)->get();
|
|
$ct = ConsumptionTimes::select('name', 'slug')->where('status', 1)->get();
|
|
|
|
$productsList = Products::where([['status', 1], ['departaimants', 1]])->get();
|
|
|
|
$departaimants = true;
|
|
$title = "Départ'Aimants";
|
|
|
|
return view('front.products.index', compact(
|
|
'productsList',
|
|
'departaimants',
|
|
'productsSlides',
|
|
'ranges',
|
|
'meatTypes',
|
|
'ct',
|
|
'title'
|
|
));
|
|
}
|
|
|
|
public function show(Products $product)
|
|
{
|
|
$recipeVideo = $product->recipe()->first();
|
|
|
|
$recipes = $product->recipes()->get();
|
|
$ids = [];
|
|
foreach ($recipes as $r) {
|
|
$ids[] = $r->id;
|
|
}
|
|
$ids = array_unique($ids);
|
|
$generalConfig = app()->view->getShared()['GeneralConfigGlobal'] ?? null;
|
|
$generalConfig = $generalConfig ? $generalConfig->where('type', GeneralConfigType::rsm())->first() : null;
|
|
$recipes = Recipes::whereIn('id', $ids)->where('status', true)->get();
|
|
|
|
return view('front.products.product', compact('product', 'recipes', 'recipeVideo', 'generalConfig'));
|
|
}
|
|
|
|
public function indexMenusAjax(Request $request)
|
|
{
|
|
if (!$request->ajax()) {
|
|
abort(400);
|
|
}
|
|
return response()->json(BalancedMenus::productsAjax());
|
|
}
|
|
}
|