mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-20 04:24:23 -08:00
88b1da4260
* Fixed missing oauth tables during setup. * Cache settings Cache the setting to reduce unnecessary database calls
41 lines
1,016 B
PHP
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);
|
|
}
|
|
}
|