Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MahmoudAdelAli's avatar

Change Locale Laravel 11

since i upgraded to Laravel 11 , i know there's no kernel.php so i decided to identify the LocalizationMiddleware class at app.php bootstrap

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append( LocalizationMiddleware::class);
    })

but it's still doesn't work so i read more and finally it works with

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->group('web', [
        StartSession::class,
        ShareErrorsFromSession::class,
        LocalizationMiddleware::class,
    ]);
    })

but for filametPhp what happened is not good , when i enter the email and password for the panel nothing happened it's redirect me back to login again , once i removed the middleware it works again , idk why that happen

#Localization Middleware
class LocalizationMiddleware
{
    public function handle(Request $request, Closure $next)
    {


        if (session()->has('locale')) {
            $locale = session()->get('locale','en');
            app()->setLocale($locale);
        }
        return $next($request);
    }
}

0 likes
3 replies
MohamedTammam's avatar
Level 51

You want to append it to the web middleware group

$middleware->appendToGroup('web', [
	LocalizationMiddleware::class,
]);

It needs to run after the web middleware default group, so it runs after the session middleware while keeping the original group middlewares.

MahmoudAdelAli's avatar

@MohamedTammam Yes, that's what I do , and it works , but it didn't affect the FilamentPANEL when the lang changes , I also added Localization Middleware to the panel.

Please or to participate in this conversation.