has('lang') && in_array($request->input('lang', 'en'), $this->locales)) { $locale = $request->input('lang'); App::setLocale($locale); } elseif (auth()->guard('contact')->user()) { auth()->guard('contact')->user()->loadMissing(['client' => function ($query) { // @phpstan-ignore method.undefined $query->without('gateway_tokens', 'documents', 'contacts.company', 'contacts'); // Exclude 'grandchildren' relation of 'client' }]); App::setLocale(auth()->guard('contact')->user()->client->locale()); } elseif (auth()->user()) { try { App::setLocale(auth()->user()->company()->getLocale()); // @phpstan-ignore method.undefined } catch (\Exception $e) { } } else { App::setLocale(config('ninja.i18n.locale')); } return $next($request); } }