@martinbean I want to filter some routes if current route name is exists in allowed routes group array then return request after converting current page into another language otherwise abort 404.
This is a custom middleware for changing pages into different language.
@JussiMannisto Sure, here ia my code, sorry for late response actually I was busy in other stuff.
public function handle($request, Closure $next)
{
$valid_routes = [
..,
...
];
if (!request()->routeIs($valid_routes)) {
// when user request spanish page that are not exists in spanish
abort_if(request()->route()->getPrefix() == '/es, 404);
app()->setLocale('en');
} else if (Cookie::has('user_preferred_language')) {
app()->setLocale(request()->route()->getPrefix() == '/es' ? 'es' : 'en');
}
return $next($request);
}