38 lines
871 B
PHP
38 lines
871 B
PHP
<?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';
|
|
if (!empty($userSetting)) {
|
|
if (!in_array($userSetting->language, ['en', 'ru', 'est'])) {
|
|
$locale = $userSetting->language;
|
|
}
|
|
}
|
|
|
|
Session::put('locale', $locale);
|
|
app()->setLocale($locale);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|