From 72f28b1794ca10da4fa3d1a5f41f5c9c59d3d727 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Thu, 7 Mar 2019 16:16:45 +0300 Subject: [PATCH] updated middleware --- src/Middleware/SetLocale.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Middleware/SetLocale.php b/src/Middleware/SetLocale.php index 99a2967..a41f5fd 100644 --- a/src/Middleware/SetLocale.php +++ b/src/Middleware/SetLocale.php @@ -2,9 +2,6 @@ namespace Akaunting\Language\Middleware; -use App; -use Auth; -use Carbon\Carbon; use Closure; use Unicodeveloper\Identify\Facades\IdentityFacade as Identify; @@ -23,7 +20,7 @@ private function setLocale($locale) } // Set app language - App::setLocale($locale); + \App::setLocale($locale); // Set carbon language if (config('language.carbon')) { @@ -32,7 +29,7 @@ private function setLocale($locale) $locale = explode('-', $locale)[0]; } - Carbon::setLocale($locale); + \Carbon\Carbon::setLocale($locale); } // Set date language @@ -57,7 +54,7 @@ public function setDefaultLocale() public function setUserLocale() { - $user = Auth::user(); + $user = auth()->user(); if ($user->locale) { $this->setLocale($user->locale); @@ -85,16 +82,13 @@ public function setSystemLocale($request) */ public function handle($request, Closure $next) { - if (Auth::check()) { + if ($request->has('lang')) { + $this->setLocale($request->get('lang')); + } elseif (auth()->check()) { $this->setUserLocale(); } else { $this->setSystemLocale($request); } - - //check lang as a passed parameter in URI - if($request->has('lang')){ - $this->setLocale($request->lang); - } return $next($request); }