问题
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