snipe-it/app/Http/Middleware/CheckLocale.php
Wes Hulette 88b1da4260 Added: Caching of settings (#6378)
* Fixed missing oauth tables during setup.

* Cache settings

Cache the setting to reduce unnecessary database calls
2018-11-01 19:59:50 -07:00

41 lines
1,016 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Config;
use App\Models\Setting;
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 ($settings = Setting::getSettings()) {
// User's preference
if (($request->user()) && ($request->user()->locale)) {
\App::setLocale($request->user()->locale);
// App setting preference
} elseif ($settings->locale != '') {
\App::setLocale($settings->locale);
// Default app setting
} else {
\App::setLocale(config('app.locale'));
}
}
\App::setLocale(config('app.locale'));
return $next($request);
}
}