snipe-it/app/Http/Middleware/CheckLocale.php

45 lines
1 KiB
PHP
Raw Normal View History

2016-03-25 01:18:05 -07:00
<?php
namespace App\Http\Middleware;
use Closure;
use Config;
use Route;
2016-05-14 15:05:28 -07:00
use Schema;
2016-03-25 19:26:22 -07:00
use App\Models\Setting;
2016-03-25 01:18:05 -07:00
class CheckLocale
{
/**
* Handle the locale for the user, default to settings otherwise
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Setting::getSettings()) {
2016-05-14 15:05:28 -07:00
// User's preference
if (($request->user()) && ($request->user()->locale)) {
\App::setLocale($request->user()->locale);
2016-03-25 01:18:05 -07:00
2016-05-14 15:05:28 -07:00
// App setting preference
} elseif ((Setting::getSettings()) && (Setting::getSettings()->locale!='')) {
\App::setLocale(Setting::getSettings()->locale);
2016-03-25 01:18:05 -07:00
2016-05-14 15:05:28 -07:00
// Default app setting
} else {
\App::setLocale(config('app.locale'));
}
2016-03-25 01:18:05 -07:00
}
2016-05-14 15:05:28 -07:00
\App::setLocale(config('app.locale'));
2016-03-25 01:18:05 -07:00
return $next($request);
}
}