1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Http/Middleware/Locale.php

49 lines
1.2 KiB
PHP
Raw Normal View History

<?php
2021-12-09 06:34:23 +01:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2021-12-09 06:34:23 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Middleware;
use Closure;
2020-10-28 11:10:49 +01:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
class Locale
{
/**
* Handle an incoming request.
*
2020-10-28 11:10:49 +01:00
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
/*LOCALE SET */
if ($request->has('lang')) {
$locale = $request->input('lang');
App::setLocale($locale);
} elseif (auth()->guard('contact')->user()) {
App::setLocale(auth()->guard('contact')->user()->client()->setEagerLoads([])->first()->locale());
} elseif (auth()->user()) {
try {
2022-01-16 09:09:46 +01:00
App::setLocale(auth()->user()->company()->getLocale());
} catch (\Exception $e) {
2022-01-16 09:09:46 +01:00
}
} else {
App::setLocale(config('ninja.i18n.locale'));
}
return $next($request);
}
}