3 namespace App\Http\Middleware;
6 use Illuminate\Http\Request;
7 use Illuminate\Support\Facades\App;
9 class LanguageMiddleware {
12 * Handle an incoming request.
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
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);
24 $lang = $request->header('Accept-Language');
25 if ($lang && in_array($lang, $this->available)) {
26 App::setLocale($lang);
27 return $next($request);
29 return $next($request);
32 private $available = ['de', 'en'];