在 laravist 的实现,大概是这样的思路, UpdatePasswordRequest.php
:
public function rules()
{
return [
'old_password' => 'required|min:6',
'password' => 'required|min:6|confirmed|different:old_password',
'password_confirmation' => 'required|min:6',
];
}
控制器的大概是这样:
public function updatePassword(Requests\UpdatePasswordRequest $request)
{
$user = Auth::user();
if ( Hash::check($request->get('old_password'), $user->password) ) {
$user->password = bcrypt($request->get('password'));
$user->save();
return redirect()->back()->with('password_update', '成功修改密码');
}
return redirect()->back()->with('password_update_failed', '修改密码失败');
}
细节你自己修正一下,比如是否使用 Request....