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

mohammadbasir's avatar

Laravel additional prefix in language

Quick question that is already killing me for days. With Laravel I am trying to use different languages.

English and Japanese

This works in the route like this.

Route::group([
    'prefix' => '{lang}',
    'where' => ['lang' => '(jp|en)'],
    'middleware' => 'Language'
], function() {
    Route::get('/blogs', 'BlogController@index')->name('main-blog');
    Route::get('/blog/{postId}/{postTitle}', 'BlogController@post'); 
});

This works when I am visiting the "/blogs" page. It changes between languages.

Now when I visit the "/blog/{postId}/{postTitle}" page I can't access the posted parameter anymore within my controller.

Somehow it only shows the "lang" parameter. What would be the right way to access a parameter when using a prefix.

When I don't use the prefix it works like a charm.

My Controller;

public function post($blog_id, $blog_title) 
{
    // Do something
}

Help is highly appreciated. I have been banging my head with this for days now.

0 likes
1 reply
tisuchi's avatar
tisuchi
Best Answer
Level 70

@mohammadbasir

You use the prefix parameter to specify common parameters for your grouped routes. So You need one more parameter $lang for this controller:

public function post($lang, $blog_id, $blog_title) 
{
    // Do something
}

With prefix parameter the routes look like these:

/{lang}/blogs
/{lang}/blog/{postId}/{postTitle}
2 likes

Please or to participate in this conversation.