123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Http\Middleware;
- use Carbon\Carbon;
- use Closure;
- use Illuminate\Auth\Access\AuthorizationException;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\App;
- class Language
- {
- /**
- * Handle an incoming request.
- *
- * @param Request $request
- * @param Closure $next
- * @param string|null $guard
- *
- * @return mixed
- *
- * @throws AuthorizationException
- */
- public function handle($request, Closure $next)
- {
- $language = $request->header('language');
- if (in_array($language, ['en', 'zh_CH']) && App::getLocale() != $language) {
- App::setLocale($language);
- }
- return $next($request);
- }
- }
|