Controller function:
public function change_email(Request $request){
// Validate email
$request->validate([
'email' => ['required', 'string', 'email', 'max:40', 'unique:users'],
'confirm_new_email' => ['required','same:email'],
]);
// User needs to enter password to change email
if(password_verify($request->password, Auth::user()->password)){
$user = Auth::user();
$user->email = $request->email;
$user->email_verified_at = null;
$user->google_id = null;
$user->save();
/* Send verification email */
$user->sendEmailVerificationNotification();
toast('Email changed','success');
return view('auth/verify');
}
toast('Wrong password','error');
return redirect()->back();
}
Post a Comment