Laravel how to add group prefix parameter to route function
15,922
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
Author by
Kalanj Djordje Djordje
Updated on July 15, 2022Comments
-
Kalanj Djordje Djordje almost 2 years
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 thisexample.com/de/about
-
Kalanj Djordje Djordje over 8 yearsI don't need to define route. I need to get url for route with other prefix.
-
Basheer Kharoti over 8 years
de
is not necessary in child routes -
Kalanj Djordje Djordje over 8 yearssorry, I little improved a question. Problem is how to generically change prefix while call route function
-
Narendrasingh Sisodia over 8 yearsBut its easy to identify @BasheerAhmed
-
Narendrasingh Sisodia over 8 years@BasheerAhmed It won't