2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Config;
|
|
|
|
use Route;
|
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)
|
|
|
|
{
|
|
|
|
|
|
|
|
// User's preference
|
|
|
|
if (($request->user()) && ($request->user()->locale)) {
|
|
|
|
\App::setLocale($request->user()->locale);
|
|
|
|
|
|
|
|
// App setting preference
|
2016-03-25 19:26:22 -07:00
|
|
|
} elseif ((Setting::getSettings()) && (Setting::getSettings()->locale!='')) {
|
|
|
|
\App::setLocale(Setting::getSettings()->locale);
|
2016-03-25 01:18:05 -07:00
|
|
|
|
|
|
|
// Default app setting
|
|
|
|
} else {
|
|
|
|
\App::setLocale(config('app.locale'));
|
|
|
|
}
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|