Function for resend email takes me to the home page and does nothing in the given function - Laravel

Viewed 61

I have this simple function on click to send email to the users if the first one after registration didnt go. But when i click on the button it doesn nothing and takes me to the home page.

The resend function:

protected function resend()
    {
        $user = Account::where('email', Auth::user()->email)->first();
        $user->verifyToken = Str::random(40);
        $user->save();

        $this->sendEmail($user);
        return redirect(route('verifyEmail'))->with('user',$user)->with('success', 'A link has been sent to your email');

    }

Route::post('/resend/email', 'Auth\RegisterController@resend')->name('resendEmail');

The html:

<form action=" {!! route('resendEmail') !!}" method="POST">
   @csrf
      <button class="btn btn-default" type="submit" value="Submit">Resend Verification Link</button>
</form>

Middleware problem fixed by adding to the constructor: $this->middleware('auth', ['except' => ['resendEmail']]);

1 Answers

Add this on RegisterController __construct method :

$this->middleware('auth', ['except' => ['account/security/resend/email']]);
Related