2019-12-10 21:25:54 +01:00
|
|
|
<?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
|
|
|
|
*/
|
2019-12-10 21:25:54 +01:00
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Http\Request;
|
2019-12-10 21:25:54 +01:00
|
|
|
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
|
2019-12-10 21:25:54 +01:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*LOCALE SET */
|
|
|
|
if ($request->has('lang')) {
|
|
|
|
$locale = $request->input('lang');
|
|
|
|
App::setLocale($locale);
|
2022-02-16 03:24:10 +01:00
|
|
|
} elseif (auth()->guard('contact')->user()) {
|
2022-02-18 06:31:17 +01:00
|
|
|
App::setLocale(auth()->guard('contact')->user()->client()->setEagerLoads([])->first()->locale());
|
2019-12-10 21:25:54 +01:00
|
|
|
} elseif (auth()->user()) {
|
2022-06-21 11:57:17 +02:00
|
|
|
try {
|
2022-01-16 09:09:46 +01:00
|
|
|
App::setLocale(auth()->user()->company()->getLocale());
|
2022-06-21 11:57:17 +02:00
|
|
|
} catch (\Exception $e) {
|
2022-01-16 09:09:46 +01:00
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-12-10 21:25:54 +01:00
|
|
|
App::setLocale(config('ninja.i18n.locale'));
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-10 21:25:54 +01:00
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|