public function handle(Request $request, Closure $next)
{
$path = ltrim($request->path(), '/');
if (
preg_match('#^[a-z]{2}(/|$)#', $path) ||
$request->is('api/*') ||
$request->is('storage/*') ||
$request->is('widget*') ||
$request->is('lang') || // skip redirection for /lang
$request->query->has('cd')
) {
return $next($request);
}
$cookieLang = $request->cookie('lang_selected');
$geoCountry = $request->header('CF-IPCountry', 'US');
$geoLang = $this->countryToLang[$geoCountry] ?? 'en';
if ($cookieLang) {
// ✅ If user selected English manually, stay on /
if ($cookieLang === 'en') {
return $next($request);
}
// ✅ Redirect to other locale if selected
return redirect("/$cookieLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''));
}
// ✅ If no cookie and GEO is not English, redirect and set cookie
if ($geoLang !== 'en') {
return redirect("/$geoLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''))
->withCookie(cookie('lang_selected', $geoLang, 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
// ✅ GEO says English — stay and set cookie
return $next($request)
->withCookie(cookie('lang_selected', 'en', 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
public function handle(Request $request, Closure $next)
{
$path = ltrim($request->path(), '/');
if (
preg_match('#^[a-z]{2}(/|$)#', $path) ||
$request->is('api/*') ||
$request->is('storage/*') ||
$request->is('widget*') ||
$request->is('lang') || // skip redirection for /lang
$request->query->has('cd')
) {
return $next($request);
}
$cookieLang = $request->cookie('lang_selected');
$geoCountry = $request->header('CF-IPCountry', 'US');
$geoLang = $this->countryToLang[$geoCountry] ?? 'en';
if ($cookieLang) {
// ✅ If user selected English manually, stay on /
if ($cookieLang === 'en') {
return $next($request);
}
// ✅ Redirect to other locale if selected
return redirect("/$cookieLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''));
}
// ✅ If no cookie and GEO is not English, redirect and set cookie
if ($geoLang !== 'en') {
return redirect("/$geoLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''))
->withCookie(cookie('lang_selected', $geoLang, 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
// ✅ GEO says English — stay and set cookie
return $next($request)
->withCookie(cookie('lang_selected', 'en', 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
public function handle(Request $request, Closure $next)
{
$path = ltrim($request->path(), '/');
if (
preg_match('#^[a-z]{2}(/|$)#', $path) ||
$request->is('api/*') ||
$request->is('storage/*') ||
$request->is('widget*') ||
$request->is('lang') || // skip redirection for /lang
$request->query->has('cd')
) {
return $next($request);
}
$cookieLang = $request->cookie('lang_selected');
$geoCountry = $request->header('CF-IPCountry', 'US');
$geoLang = $this->countryToLang[$geoCountry] ?? 'en';
if ($cookieLang) {
// ✅ If user selected English manually, stay on /
if ($cookieLang === 'en') {
return $next($request);
}
// ✅ Redirect to other locale if selected
return redirect("/$cookieLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''));
}
// ✅ If no cookie and GEO is not English, redirect and set cookie
if ($geoLang !== 'en') {
return redirect("/$geoLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''))
->withCookie(cookie('lang_selected', $geoLang, 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
// ✅ GEO says English — stay and set cookie
return $next($request)
->withCookie(cookie('lang_selected', 'en', 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
Server Error
public function handle(Request $request, Closure $next)
{
$path = ltrim($request->path(), '/');
if (
preg_match('#^[a-z]{2}(/|$)#', $path) ||
$request->is('api/*') ||
$request->is('storage/*') ||
$request->is('widget*') ||
$request->is('lang') || // skip redirection for /lang
$request->query->has('cd')
) {
return $next($request);
}
$cookieLang = $request->cookie('lang_selected');
$geoCountry = $request->header('CF-IPCountry', 'US');
$geoLang = $this->countryToLang[$geoCountry] ?? 'en';
if ($cookieLang) {
// ✅ If user selected English manually, stay on /
if ($cookieLang === 'en') {
return $next($request);
}
// ✅ Redirect to other locale if selected
return redirect("/$cookieLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''));
}
// ✅ If no cookie and GEO is not English, redirect and set cookie
if ($geoLang !== 'en') {
return redirect("/$geoLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''))
->withCookie(cookie('lang_selected', $geoLang, 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
// ✅ GEO says English — stay and set cookie
return $next($request)
->withCookie(cookie('lang_selected', 'en', 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
public function handle(Request $request, Closure $next)
{
$path = ltrim($request->path(), '/');
if (
preg_match('#^[a-z]{2}(/|$)#', $path) ||
$request->is('api/*') ||
$request->is('storage/*') ||
$request->is('widget*') ||
$request->is('lang') || // skip redirection for /lang
$request->query->has('cd')
) {
return $next($request);
}
$cookieLang = $request->cookie('lang_selected');
$geoCountry = $request->header('CF-IPCountry', 'US');
$geoLang = $this->countryToLang[$geoCountry] ?? 'en';
if ($cookieLang) {
// ✅ If user selected English manually, stay on /
if ($cookieLang === 'en') {
return $next($request);
}
// ✅ Redirect to other locale if selected
return redirect("/$cookieLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''));
}
// ✅ If no cookie and GEO is not English, redirect and set cookie
if ($geoLang !== 'en') {
return redirect("/$geoLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''))
->withCookie(cookie('lang_selected', $geoLang, 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
// ✅ GEO says English — stay and set cookie
return $next($request)
->withCookie(cookie('lang_selected', 'en', 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
public function handle(Request $request, Closure $next)
{
$path = ltrim($request->path(), '/');
if (
preg_match('#^[a-z]{2}(/|$)#', $path) ||
$request->is('api/*') ||
$request->is('storage/*') ||
$request->is('widget*') ||
$request->is('lang') || // skip redirection for /lang
$request->query->has('cd')
) {
return $next($request);
}
$cookieLang = $request->cookie('lang_selected');
$geoCountry = $request->header('CF-IPCountry', 'US');
$geoLang = $this->countryToLang[$geoCountry] ?? 'en';
if ($cookieLang) {
// ✅ If user selected English manually, stay on /
if ($cookieLang === 'en') {
return $next($request);
}
// ✅ Redirect to other locale if selected
return redirect("/$cookieLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''));
}
// ✅ If no cookie and GEO is not English, redirect and set cookie
if ($geoLang !== 'en') {
return redirect("/$geoLang/" . $path . ($request->getQueryString() ? '?' . $request->getQueryString() : ''))
->withCookie(cookie('lang_selected', $geoLang, 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
// ✅ GEO says English — stay and set cookie
return $next($request)
->withCookie(cookie('lang_selected', 'en', 525600, '/', '.currency.wiki', true, false, false, 'Lax'));
}
Server Error