]> git.localhorst.tv Git - alttp.git/blob - app/Http/Middleware/LanguageMiddleware.php
better schedule start
[alttp.git] / app / Http / Middleware / LanguageMiddleware.php
1 <?php
2
3 namespace App\Http\Middleware;
4
5 use Closure;
6 use Illuminate\Http\Request;
7 use Illuminate\Support\Facades\App;
8
9 class LanguageMiddleware {
10
11         /**
12          * Handle an incoming request.
13          *
14          * @param  \Illuminate\Http\Request  $request
15          * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
16          * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
17          */
18         public function handle(Request $request, Closure $next) {
19                 $lang = $request->input('lng');
20                 if ($lang && in_array($lang, $this->available)) {
21                         App::setLocale($lang);
22                         return $next($request);
23                 }
24                 $lang = $request->header('Accept-Language');
25                 if ($lang && in_array($lang, $this->available)) {
26                         App::setLocale($lang);
27                         return $next($request);
28                 }
29                 return $next($request);
30         }
31
32         private $available = ['de', 'en'];
33
34 }