我想用Laravel 5创建一个包含3个字段(旧密码、新密码、确认密码)的表单。
视图
旧密码:
{!! Form::password('old_password',['class' => 'form-control']) !!}
新密码:
{!! Form::password('password',['class' => 'form-control']) !!}
确认新密码:
{!! Form::password('verify_password',['class' => 'form-control']) !!}
当用户注册时的控制器
public function postRegister(Request $request)
{
$rules = [
'email' => 'required|email|unique:users',
'confirm_email' => 'required|same:email',
'password' => 'required|min:8|regex:/^(?=\S*[a-z])(?=\S*[!@#$&*])(?=\S*[A-Z])(?=\S*[\d])\S*$/',
'verify_password' => 'required|same:password',
];
$messages = [
'email.required' => 'email tidak boleh kosong',
'password.required' => 'password tidak boleh kosong',
'password.min' => 'Password harus minimal 8 karakter',
'password.regex' => 'Format password harus terdiri dari kombinasi huruf besar, angka dan karakter spesial (contoh:!@#$%^&*?><).',
'verify_password.required' => 'Verify Password tidak boleh kosong',
'email.email' => 'Format Email tidak valid',
'email.unique' => 'Email yang anda masukkan telah digunakan',
'verify_password.same' => 'Password tidak sama!',
];
$this->validate($request,$rules,$messages);
$newUser = $this->user->create([
'email' => $request->email,
'password' => \Hash::make($request->password),
]);
$this->activationService->sendActivationMail($newUser);
return redirect('/account/login')->with('success', 'Check your email');
}
我是laravel的新手,我在stackoverflow上读了一些类似的更改密码问题,但它们并没有帮助到我。
我应该如何在我的控制器中编写代码来更改用户的密码?谢谢提前。
vendor\laravel\framework\src\Illuminate\Foundation\Auth\ResetsPasswords\PasswordController.php
页面。 - Manish