Created
November 4, 2021 09:26
-
-
Save koyablue/860ff2f0cdde0dc7d3d2433b83decf6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Packages\FrontPage\Home\Presentation\Middleware; | |
use Closure; | |
use Illuminate\Http\Request; | |
use App\Packages\FrontPage\Shared\UseCase\LocaleSessionInterface; | |
class SetLocaleMiddleware | |
{ | |
private LocaleSessionInterface $localeSession; | |
public function __construct(LocaleSessionInterface $localeSession) | |
{ | |
$this->localeSession = $localeSession; | |
} | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle(Request $request, Closure $next) | |
{ | |
$sessionKey = $this->localeSession->getLocaleSessionKey(); | |
if (session()->has($sessionKey)) { | |
app()->setLocale(session($sessionKey)); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment