1 回答

TA貢獻1770條經驗 獲得超3個贊
您需要更改您的changemailPost功能。嘗試這個 -
public function changeemailPost(Request $request)
{
? ? if (!(Hash::check($request->get('email'), Auth::user()->email))) {
? ? ? ? return redirect()->back()->with("error","Your current e-mail does not matches with the e-mail you provided. Please try again.");
? ? }
? ? if(strcmp($request->get('email'), $request->get('new-email')) == 0){
? ? ? ? return redirect()->back()->with("error","New e-mail cannot be same as your current e-mail. Please choose a different e-mail.");
? ? }
? ? ? ? $validate = $request->validate([
? ? ? ? ? ? 'new-email' => 'required|string|min:6|confirmed',
? ? ? ? ? ? 'new-email_confirmation' => 'required|string|min:6',
? ? ? ? ]);
? ? ? ? $user = Auth::user();
? ? ? ? $user->email = $request['new-email'];
? ? ? ? $user->save();
? ? ? ? Auth::logout();
? ? ? ? return view('auth.login');
? ? }
你的 HTML 如下所示 -
<form method="POST" action="{{ route('change-emailPost') }}">
? ? ? ? ? ? ? ? ? ? ? ? @csrf
? ? ? ? ? ? ? ? ? ? ? ? <label>Enter your old e-mail:</label>
? ? ? ? ? ? ? ? ? ? ? ? <fieldset class="youplay-input">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="current-email" type="email" class="form-control" placeholder="Current E-Mail" name="email" required>
? ? ? ? ? ? ? ? ? ? ? ? </fieldset>
? ? ? ? ? ? ? ? ? ? ? ? <label>Enter your new e-mail:</label>
? ? ? ? ? ? ? ? ? ? ? ? <fieldset class="youplay-input">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="new-email" type="email" placeholder="New E-Mail" class="form-control" name="new-email" required>
? ? ? ? ? ? ? ? ? ? ? ? </fieldset>
? ? ? ? ? ? ? ? ? ? ? ? <fieldset class="youplay-input">
? ? ? ? ? ? ? ? ? ? ? ? ? ? <input id="new-email-confirm" type="email" class="form-control" placeholder="Confirm New E-Mail" name="new-email_confirmation" required>
? ? ? ? ? ? ? ? ? ? ? ? </fieldset>
? ? ? ? ? ? ? ? ? ? ? ? <button type="submit" class="btn btn-default db">
? ? ? ? ? ? ? ? ? ? ? ? ? ? Change E-Mail
? ? ? ? ? ? ? ? ? ? ? ? </button>
? ? ? ? ? ? ? ? ? ? </form>
如果要比較兩個輸入字段a & b的值和confirmed驗證規則b字段應重命名為b_confirmation.
- 1 回答
- 0 關注
- 140 瀏覽
添加回答
舉報