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

jhyaps's avatar

Incorrect URL Redirections in Multi-language Login

I'm facing an issue with my Laravel application's login flow, especially when it comes to multi-language support. Here's what's happening:

In my application, I've set up Laravel Fortify for user authentication, along with multi-language support using language prefixes in the URL (e.g., /en for English and /np for Nepali).

By default, English is set as the application's default language (/en). However, I've configured my routes to redirect to the Nepali language page (/np) as the landing page.

Route::get('/', function () {
    return redirect('/np');
});

The login form is accessible via localized URLs, such as http://localhost/laravel-inventory/en/login for English and http://localhost/laravel-inventory/np/login for Nepali.

The issue arises when I submit the login form from the Nepali language page (/np/login). After successful login, instead of redirecting me to the Nepali dashboard (/np/dashboard), it redirects me to the English dashboard (/en/dashboard), which is incorrect. I want the dashboard to open in the same language as the login page.

i have also set a middleware

class SetLocale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        App::setlocale($request->locale);
        return $next($request);
    }
}

and wrap the middleware in the route

Route::get('/', function () {
    return redirect('/np');
});

Route::get('/dashboard', function () {

    return redirect(app()->getLocale() . '/dashboard');
});

Route::group(['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}'], 'middleware' => SetLocale::class], function () {

    Route::get('/', function () {
        return view('auth.login');
    });

    Route::middleware('auth')->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

		#my rest of route

});

});

I followed many suggestion from forum and youtube, but still i cannot solve my issue. Any help or insights would be greatly appreciated!.

0 likes
2 replies
MohamedTammam's avatar
Level 51

Create custom redirection for fortify after login.

$this->app->instance(LoginResponse::class, new class implements LoginResponse {
        public function toResponse($request)
        {
            return redirect(app()->getLocale() . '/dashboard');
        }
    });

https://laravel.com/docs/11.x/fortify#customizing-authentication-redirects

And I suggest that you store the local in the session and create a middleware that takes it from the session if it doesn't exist in the request to manage these cases with other packages in the future.

2 likes
Snapey's avatar

might help if you dont run the application in a subfolder

You say redirect to /np/login

How is that going to work when it needs to be /laravel-inventory/np/login

Set document root to be the public folder within your project

1 like

Please or to participate in this conversation.