polisplexity.tech/app/Http/Middleware/LanguageMiddleware.php

30 lines
755 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\App;
class LanguageMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
// Check if the 'lang' parameter is present in the URL
if ($request->has('lang')) {
$lang = $request->lang;
} else {
// Default to English if no 'lang' parameter is found
$lang = 'en';
}
App::setLocale($lang);
return $next($request);
}
}