Laravel change locale not working
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
In this blog post, we will dive into understanding why your code for changing locale in Laravel may not be functioning as expected when working with a dropdown list containing English and Dutch languages. We'll provide a thorough analysis of the problem, share relevant code examples, and give you practical solutions to ensure your application can adapt to different language preferences.
Problem Analysis: The issue may arise due to a combination of factors: incorrect routing, inadequate HTML form structure for selecting languages, or improper setup of language files. Let's dissect these possibilities one by one.
1. Routing Issues: Ensure that your routing matches the expected path. In this case, the codeRoute::post('/locale', function(){ seems to be set up correctly. However, further investigation into your project's structure might reveal that Laravel is not aware of the resources folder or its location could be inconsistent across different languages.
2. HTML Form Structure: Check if the dropdown list for selecting language options has been properly coded. The example code provided should work if correctly placed within a form tag:
3. Language Files Setup: Laravel supports multiple languages by using specific language files for each localization. In your project, the navigation.php file might be located in different directories based on the language and path. However, it's essential to ensure that the names of the language paths (du for Dutch and en for English) are consistent across all navigation files.
php
resources/
/du
navigation.php
/en
navigation.phpphp
Route::post('/locale', function(){
\App::setLocale(Request::Input('locale'));
return redirect()->back();
});php
Route::post('/locale', function () {
$inputLocale = Request::Input('locale');
if (strtolower($inputLocale) === 'en') {
\Config::set('app.locale', 'en');
} elseif ($inputLocale === 'du') {
\Config::set('app.locale', 'du');
} else {
throw new InvalidArgumentException();
}
return redirect()->back();
});