R
R
Rukis2018-10-07 13:48:33
Laravel
Rukis, 2018-10-07 13:48:33

How to remove localizations in laravel controllers?

laravel 5.7.6
All routes wrapped in a group

Route::group(['prefix' => '{locale}', 'middleware' => 'locale'], function () {
//....
});

that is, all urls start with the prefix ru, en, etc. (site.com/ru/catalog) the prefix is ​​processed in the middleware and there is no need to inject it into the controller, and I would like to do this:
public function edit(User $user)
    {
        //
    }

But, due to the fact that locale is still passed to all controllers, you have to specify it in the input parameters so that there is no error:
public function edit($locale, User $user)
    {
        //
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2018-10-07
@rukis

In middleware BEFORE calling $next($request):
$request->route()->forgetParameter('locale');

D
Dmitry, 2018-10-08
@Astatroth

So don't prefix the route group. Why not use a package for localization?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question