Aknaproff/app/Http/Middleware/LocaleMiddleware.php

38 lines
871 B
PHP
Raw Normal View History

2024-03-13 05:31:30 +00:00
<?php
namespace App\Http\Middleware;
use App\UserSetting;
use Closure;
use Illuminate\Support\Facades\Session;
class LocaleMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (empty(Session::get('locale'))) {
$userSetting = UserSetting::where('user_id', auth()->user()->id)->first();
$locale = 'en';
2024-03-17 12:40:23 +00:00
if (!empty($userSetting)) {
if (!in_array($userSetting->language, ['en', 'ru', 'est'])) {
$locale = $userSetting->language;
}
2024-03-13 05:31:30 +00:00
}
2024-03-17 12:40:23 +00:00
2024-03-13 05:31:30 +00:00
Session::put('locale', $locale);
app()->setLocale($locale);
}
return $next($request);
}
}