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

Lacikkaa's avatar

Mcamara - Laravel Localization

Hello! When i use in my routes.php:

Route::get('/about', function()
        {
            return View::make('welcome');
        });

I get the correct link in the browser: 'project.dev/hu/about'

But when i use this:

Route::get(LaravelLocalization::transRoute('routes.about') , ['as'=>'about....

I get this link: 'project.dev/about' without the language prefix and the 'Sorry, the page you are looking for could not be found' message.

What i do wrong?

0 likes
9 replies
ekhlas's avatar

hi

Route::group(
[
    'prefix' => LaravelLocalization::setLocale(),
    'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ]
],
function(){
   
   Route::get('/about', function()
        {
            return View::make('welcome');
        });
});
Lacikkaa's avatar

Yes, and it works! But i would like to use the transRoute, which is not work. :(

ekhlas's avatar

hi

Route::group(
[
    'prefix' => LaravelLocalization::setLocale(),
    'middleware' => [ 'localize' ] // Route translate middleware
],
function() {
    /** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
    Route::get('/', function() {
        // This routes is useless to translate
        return View::make('hello');
    });

    Route::get(LaravelLocalization::transRoute('routes.about'), function() {
        return View::make('about');
    });

    Route::get(LaravelLocalization::transRoute('routes.view'), function($id) {
        return View::make('view',['id'=>$id]);
    });
});

Lacikkaa's avatar

Yes, this is not working. Read a documentation a lot, where i made a mistake and nothing. I add these middlewares to kernel.

protected $routeMiddleware = [
        'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
        'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
        'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
        'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class,
    ];
ekhlas's avatar

hi @Lacikkaa

change this

'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,

to

protected $routeMiddleware = [
        /**** OTHER MIDDLEWARE ****/
        'localize' => 'Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes',
        // TRANSLATE ROUTES MIDDLEWARE
    ];

remove below

 'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
        'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
        'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class,
Lacikkaa's avatar

hi @ekhlas ,

No, not working, I try to use another localization.

But, thanks your answers.

Lacikkaa's avatar

I'm a noob in laravel yet!

I think the problem is on the blade template link. Please write an semple with translated route name...

Lacikkaa's avatar

Nothing! I made a correct links and it works.

Thank all of the answers!

Please or to participate in this conversation.