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

47 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
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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;
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);
}
}