4

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.

Wesley

2
  • Something doesn't add up here. The route you're having trouble with is pointing to post() method, but your controller doesn't seem to implement one from the code you posted. Commented May 22, 2019 at 3:24
  • Indeed I made a mistake with writing the example. Have updated it. Commented May 22, 2019 at 4:13

1 Answer 1

1

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}
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed! I should smack myself in the face. The answer was so easy, I just made a dumb mistake. Maybe better to take some off next time after hours of scripting. You are my hero! Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.