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

≯℡__Kan透↙ 提交于 2021-02-10 03:26:19

问题


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:


Add this on RegisterController __construct method :

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


来源:https://stackoverflow.com/questions/62918111/function-for-resend-email-takes-me-to-the-home-page-and-does-nothing-in-the-give

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!