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);