0
votes

using Laravel 7.19

all my routes require a locale , including my Auth Routes to support different languages. And I've activated email verficitation for the users.

So once a user , that didn't verfiy his email , tries to open a part of my website that requires email verficitation Laravel automatically redirects them to this route : verification.notice

The Problem is that the route requires the locale parameter but I don't know how to pass the locale to the route. So I'm getting this error message

Missing required parameters for [Route: verification.notice] [URI: {locale}/email/verify]. 

Anyone knows the function that redirects me to the route : verification.notice ? Because I need to adjust or overwrite it so I can pass the locale parameter to it.

My web.php

Route::group(['middleware' => ['setlocale'],'prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}']], function() {

Auth::routes(['verify' => true]);   
    
});

EDIT : Found Something usefule . Inside the File /vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php

There's a function handle

If I add app()->getLocale() to it , the error message is gone. Looking like this now

public function handle($request, Closure $next, $redirectToRoute = null)
    {
        if (! $request->user() ||
            ($request->user() instanceof MustVerifyEmail &&
            ! $request->user()->hasVerifiedEmail())) {
            return $request->expectsJson()
                    ? abort(403, 'Your email address is not verified.')
                    : Redirect::route($redirectToRoute ?: 'verification.notice',app()->getLocale());
        }

        return $next($request);
    }

But I don't don't think you're supposed to make changes to /vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php

How do I correctly overwrite this function ?

1

1 Answers

0
votes

Sounds like you have to copy that middleware code and amend it that way. Simply copy the code of Illuminate\Auth\Middleware\EnsureEmailsVerified.php from the vendor dir (which you should never edit itself by the way), create a new middleware in App\Http\Middleware and add it to App\Http\Kernel.

The verification.notice route you're seeing is added using Auth::routes(['verify' => true]); (its part a set of default routes for authentication/verification) as seen here: https://github.com/laravel/ui/blob/2.x/src/AuthRouteMethods.php#L84 (which is part of the laravel/ui package).