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!.