Skip to content

Instantly share code, notes, and snippets.

@koyablue
Created November 4, 2021 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koyablue/860ff2f0cdde0dc7d3d2433b83decf6e to your computer and use it in GitHub Desktop.
Save koyablue/860ff2f0cdde0dc7d3d2433b83decf6e to your computer and use it in GitHub Desktop.
<?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