$user]); } public function verify(Request $request, User $user): RedirectResponse { $record = OtpVerificationToken::where('email', $user->email)->first(); if (! $record || ! Hash::check($request->otp, $record->token)) { return back()->with(['error' => "The provided otp doesn't match our records"]); } if ($record->isExpired()) { $record->delete(); return back()->with(['error' => 'OTP expired! Please request a new one']); } $payload = Crypt::decrypt($record->payload); $user->update($payload); $record->delete(); return to_route('profile.edit')->with(['success' => 'Profile updated successfully!']); } public function resend(User $user): RedirectResponse { $otp = static::generate(); OtpVerificationToken::updateOrInsert( ['email' => $user->email], [ 'token' => Hash::make($otp), 'created_at' => now(), ], ); $user->notify(new EmailUpdated($user->email, $otp)); return back()->with(['success' => 'A new otp has been sent to your email address']); } }