2019-12-10 21:25:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use App\Models\Language;
|
|
|
|
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);
|
|
|
|
} elseif (auth('contact')->user()) {
|
|
|
|
App::setLocale(auth('contact')->user()->client->locale());
|
|
|
|
} elseif (auth()->user()) {
|
|
|
|
App::setLocale(auth()->user()->company()->getLocale());
|
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);
|
|
|
|
}
|
|
|
|
}
|