1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Http/Middleware/VendorLocale.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2022-06-13 11:59:24 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
class VendorLocale
{
/**
* Handle an incoming request.
*
* @param Request $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
2022-06-15 13:24:30 +02:00
if (auth()->guard('contact')->check()) {
auth()->guard('contact')->logout();
$request->session()->invalidate();
}
2022-06-13 11:59:24 +02:00
/*LOCALE SET */
if ($request->has('lang')) {
$locale = $request->input('lang');
App::setLocale($locale);
} elseif (auth()->guard('vendor')->user()) {
App::setLocale(auth()->guard('vendor')->user()->company->locale());
} elseif (auth()->user()) {
try {
2022-06-13 11:59:24 +02:00
App::setLocale(auth()->user()->company()->getLocale());
} catch (\Exception $e) {
2022-06-13 11:59:24 +02:00
}
} else {
App::setLocale(config('ninja.i18n.locale'));
}
return $next($request);
}
}