I'm trying to use Laravel wrapped in a prefix group for localization purposes Auth::routes()
:
Route::group(['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}']], function () { Auth::routes(); });
In my views, I now provide the current language when creating routes, like this route('password.confirm', app()->getLocale())
But when I try to use the "Forgot Password" feature, an exception is thrown. I think this is because Laravel creates a password reset link internally, using a named route without passing the current language parameter.
Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameter for [Route: password.reset] [URI: {locale}/password/reset/{token}] [Missing parameter: locale].
Is it possible to use Auth::routes()
somehow globally and inject the missing "locale" parameter? Or what is the recommended approach without overriding Laravel's authentication method?
I found a solution. Thanks for this answer https://stackoverflow.com/a/49380950/9405862 It inspired me to add a middleware to my routing group that adds the missing parameters to the URL:
My middleware now looks like this: