/** * @param Request $request * @param AppMailer $mailer * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * * It does not work unless you are logged in for now => need to set up the guard in root.php * */ public function postResetEmail(Request $request, AppMailer $mailer) { // validate if it's email or not // validate if it's already in the database $this->validate($request, ['email' => 'required|email|unique:users']); // create a token // create a reacord using User class // email, token, 'created_at $user_id = \Auth::user()->id; $email = $request['email']; $token = $this->createNewToken(); $created_at = \Carbon\Carbon::now(); // CRATE EMAIL RESET MODEL $reset_data = new \App\Email_address_reset(compact('user_id', 'email', 'token', 'created_at')); \App\Email_address_reset::create($reset_data->toArray()); // send an email with a link with the token using helper method $mailer->sendEmailConfirmationForResettingEmailWith($reset_data); // flash the message too flash('Sent an Email with a link, please click the link and activate your new email address'); //redirect to the current page return redirect('/reset/email'); }