Laravel how to add group prefix parameter to route function

- 1 answer

Ad

For example, I have defined routes like this:

$locale = Request::segment(1);

Route::group(array('prefix' => $locale), function()
{
  Route::get('/about', ['as' => 'about', 'uses' => '[email protected]']);
}

I want to generate links for several locales (en, de, es,...). When I try to provide prefix parameter like this

$link = route('about',['prefix' => 'de']);

I got link like this example.com/en/about?prefix=de How to provide prefix param to got link like this example.com/de/about

Ad

Answer

Ad

You can play around with something like this perhaps.

Route::group(['prefix' => '{locale}'], function () {
    Route::get('about', ['as' => 'about', 'uses' => '....']);
});

route('about', 'en');  // http://yoursite/en/about
route('about', 'de');  // http://yoursite/de/about
Ad
source: stackoverflow.com
Ad