ldc-doux/app/Http/Middleware/InitVarsGlobals.php
2022-02-01 12:44:02 +01:00

111 lines
4.4 KiB
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use App\Enums\Page;
use App\Models\Advice;
use App\Models\Encart;
use App\Models\Gamme;
use App\Models\Moment;
use App\Models\Picto;
use App\Models\PictoBrand;
use App\Models\Post;
use App\Models\Product;
use App\Models\Text;
use App\Models\Title;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\View;
class InitVarsGlobals
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$encart_home = Encart::where('page', Page::homeHeader()->value)->first();
$encart_marqueHeader = Encart::where('page', Page::marqueHeader()->value)->first();
$encart_marqueBloc2 = Encart::where('page', Page::marqueBloc2()->value)->first();
$encart_marqueBloc3 = Encart::where('page', Page::marqueBloc3()->value)->first();
$encart_marqueBloc4l = Encart::where('page', Page::marqueBloc4l()->value)->first();
$encart_marqueBloc4r = Encart::where('page', Page::marqueBloc4r()->value)->first();
$encart_marqueFooter = Encart::where('page', Page::marqueFooter()->value)->first();
$encart_food = Encart::where('page', Page::foodHeader()->value)->first();
$mentions_legales = Text::where('page', Page::mentions()->value)->first();
$privacy_policy = Text::where('page', Page::charte()->value)->first();
$pictobrands_marque = PictoBrand::all();
$advice_news = Advice::all()->first();
$posts = Post::where([
['date_start', '<=', Carbon::now()->format('Y-m-d H:i:s')],
['date_end', '>', Carbon::now()->format('Y-m-d H:i:s')],
])
->orderBy('created_at', 'DESC')
->get();
$post_home = Post::where([
['date_start', '<=', Carbon::now()->format('Y-m-d H:i:s')],
['date_end', '>', Carbon::now()->format('Y-m-d H:i:s')],
['on_top', true]
])->first();
// Limitation à 3 produits affichés sur la homepage
$products_home = Product::where('is_on_top', true)->take(3)->get();
// Limitation à 6 produits affichés sur la page Food Service
$products_food = Product::where('is_food_service', true)->take(6)->get();
$pictos_marqueBloc2 = Picto::where('page', Page::marqueBloc2()->value)->get();
$pictos_food = Picto::where('page', Page::foodBloc2()->value)->get();
$texts_news = Text::where('page', Page::newsQuestions()->value)->get();
$title_marqueBloc2 = Title::where('page', Page::marqueBloc2()->value)->first();
$title_marqueBloc4 = Title::where('page', Page::marqueBloc4()->value)->first();
$title_foodBloc2 = Title::where('page', Page::foodBloc2()->value)->first();
$title_newsPosts = Title::where('page', Page::newsPosts()->value)->first();
$moments = Moment::where('page', Page::marqueHistory()->value)->get();
View::share('encart_home', $encart_home);
View::share('encart_marqueHeader', $encart_marqueHeader);
View::share('encart_marqueBloc2', $encart_marqueBloc2);
View::share('encart_marqueBloc3', $encart_marqueBloc3);
View::share('encart_marqueBloc4l', $encart_marqueBloc4l);
View::share('encart_marqueBloc4r', $encart_marqueBloc4r);
View::share('encart_marqueFooter', $encart_marqueFooter);
View::share('encart_food', $encart_food);
View::share('pictobrands_marque', $pictobrands_marque);
View::share('post_home', $post_home);
View::share('posts', $posts);
View::share('products_home', $products_home);
View::share('products_food', $products_food);
View::share('advice_news', $advice_news);
View::share('pictos_marqueBloc2', $pictos_marqueBloc2);
View::share('pictos_food', $pictos_food);
View::share('texts_news', $texts_news);
View::share('title_marqueBloc2', $title_marqueBloc2);
View::share('title_marqueBloc4', $title_marqueBloc4);
View::share('title_foodBloc2', $title_foodBloc2);
View::share('title_newsPosts', $title_newsPosts);
View::share('moments', $moments);
View::share('mentions_legales', $mentions_legales);
View::share('privacy_policy', $privacy_policy);
return $next($request);
}
}