Skip to content

Commit

Permalink
updated middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Mar 7, 2019
1 parent 9c86923 commit 72f28b1
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/Middleware/SetLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Akaunting\Language\Middleware;

use App;
use Auth;
use Carbon\Carbon;
use Closure;
use Unicodeveloper\Identify\Facades\IdentityFacade as Identify;

Expand All @@ -23,7 +20,7 @@ private function setLocale($locale)
}

// Set app language
App::setLocale($locale);
\App::setLocale($locale);

// Set carbon language
if (config('language.carbon')) {
Expand All @@ -32,7 +29,7 @@ private function setLocale($locale)
$locale = explode('-', $locale)[0];
}

Carbon::setLocale($locale);
\Carbon\Carbon::setLocale($locale);
}

// Set date language
Expand All @@ -57,7 +54,7 @@ public function setDefaultLocale()

public function setUserLocale()
{
$user = Auth::user();
$user = auth()->user();

if ($user->locale) {
$this->setLocale($user->locale);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 72f28b1

Please sign in to comment.