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 关注
- 114 浏览
添加回答
举报