From f7e7131e46a47695b955e7de4c3cd8f46fd11faa Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Fri, 5 Aug 2016 10:34:14 +0100 Subject: [PATCH] Updating the LocaleCookieRedirect Middleware --- src/Middleware/LocaleCookieRedirect.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Middleware/LocaleCookieRedirect.php b/src/Middleware/LocaleCookieRedirect.php index e52977e..63b7411 100644 --- a/src/Middleware/LocaleCookieRedirect.php +++ b/src/Middleware/LocaleCookieRedirect.php @@ -32,21 +32,13 @@ public function handle(Request $request, Closure $next) $locale = $request->cookie('locale', null); if (localization()->isLocaleSupported($segment)) { - cookie('locale', $segment); - - return $next($request); - } - elseif (localization()->isDefaultLocaleHiddenInUrl()) { - $locale = localization()->getDefaultLocale(); - cookie('locale', $locale); + return $next($request)->withCookie(cookie()->forever('locale', $segment)); } - if (is_string($locale) && ! $this->isDefaultLocaleHidden($locale)) { - session()->reflash(); - - $redirect = $this->getLocalizedRedirect($locale); - - if ( ! is_null($redirect)) return $redirect; + if ($locale !== null && ! $this->isDefaultLocaleHidden($locale)) { + if ( ! is_null($redirect = $this->getLocalizedRedirect($locale))) { + return $redirect->withCookie(cookie()->forever('locale', $segment)); + } } return $next($request);