Answer the question
In order to leave comments, you need to log in
How to automatically add an optional parameter for every generated URL in Laravel 5?
I have a route like this:
Route::group([
'prefix' => '{lang?}',
'as' => 'frontend.',
'namespace' => 'Frontend'
],
function ()
{
Route::get('articles', [
'as' => 'articles',
'uses' => '[email protected]'
]);
});
Answer the question
In order to leave comments, you need to log in
I used the mcamara / laravel-localization package, it turns out that this is already implemented ...
I would generate a url in the model like
public function route(array $params = [], $absolute_url = true) {
$params = array_diff($params, ['', null]);
return route('frontend.articles', array_replace($params, ['prefix' => App::getLocale()]), $absolute_url);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question