Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel how to add group prefix parameter to route function

For example, I have defined routes like this:

$locale = Request::segment(1);

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

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

like image 874
Kalanj Djordje Djordje Avatar asked Dec 25 '15 09:12

Kalanj Djordje Djordje


1 Answers

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
like image 140
lagbox Avatar answered Nov 01 '22 18:11

lagbox