Is there a way of having links not use something like this?
<li><a href="/{{ LaravelLocalization::getCurrentLocale() }}">{{ trans('kotoba::general.home') }}</a></li>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to accomplish:
What I have in code:
kernel.php
protected $routeMiddleware = [
// Locale REDIRECTION MIDDLEWARE
'localize' => 'Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes',
'localizationRedirect' => 'Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter',
'localeSessionRedirect' => 'Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect'
routes.php
Route::group(['prefix' => LaravelLocalization::setLocale()], function()
{
//------- ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP -------//
Route::get('/', 'HomeController@index');
Route::get('home', 'HomeController@index');
Route::get('welcome', 'WelcomeController@index');
});
config/laravellocalization.php
'useAcceptLanguageHeader' => true,
'hideDefaultLocaleInURL' => true,
What is happening: The language selector uses code as per readme and will switch the url to "es/home" and will translate the page correctly. When I click on the link "/home" the language returns to English.
What am I doing wrong? Do I need to code or set my urls a certain way? If so would you mind providing some code?
I did look at the blog app that mcamara has in his repositories but it sets all urls as "en/home" or "es/home" which isn't really what I am trying to do so I didn't download and install to use as a learning source.
Thanks!
I had the same problem, just delete the 'localizationRedirect' and magically worked!
Please or to participate in this conversation.