55 lines
2 KiB
PHP
55 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Support\Facades\View;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class FrontEndGlobals
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
// header menu
|
|
$currentRoute = Route::current()->getName();
|
|
$routeParamsFR = Route::current()->parameters();
|
|
$routeParamsEN = $routeParamsFR;
|
|
$routeParamsES = $routeParamsFR;
|
|
array_walk($routeParamsFR, array($this, 'unbind'), '');
|
|
array_walk($routeParamsEN, array($this, 'unbind'), 'en');
|
|
array_walk($routeParamsES, array($this, 'unbind'), 'es');
|
|
if (preg_match('/^(en|es)/', $currentRoute)) {
|
|
$currentRouteFR = preg_replace('/^(en|es)\./', '', $currentRoute, 1);
|
|
$currentRouteEN = preg_replace('/^(en|es)/', 'en', $currentRoute, 1);
|
|
$currentRouteES = preg_replace('/^(en|es)/', 'es', $currentRoute, 1);
|
|
} else {
|
|
$currentRouteFR = $currentRoute;
|
|
$currentRouteEN = 'en.' . $currentRoute;
|
|
$currentRouteES = 'es.' . $currentRoute;
|
|
}
|
|
|
|
View::share('currentRouteFR', $currentRouteFR);
|
|
View::share('currentRouteEN', $currentRouteEN);
|
|
View::share('currentRouteES', $currentRouteES);
|
|
View::share('routeParamsFR', $routeParamsFR);
|
|
View::share('routeParamsEN', $routeParamsEN);
|
|
View::share('routeParamsES', $routeParamsES);
|
|
|
|
return $next($request);
|
|
}
|
|
|
|
public function unbind(&$item, $k, $lang)
|
|
{
|
|
if ($k == 'gammeSlug' || $k == 'productSlug') {
|
|
$item = $item->getTranslation('slug', $lang);
|
|
}
|
|
}
|
|
}
|