你必須做這樣的事情到您的編輯驗證
'password' => 'min:6|max:50',
所以用戶傾斜發送一個空密碼到您的分貝:
如果你想在你更新用戶密碼之前檢查,最好在你的視圖中有另一個字段爲Old_password,這樣你就可以檢查用戶是否記得舊密碼並且可以將它更改爲新密碼。 這裏是我的例子我的更新功能:
public function update(Request $request, $id)
{
$update_user = Validator::make($request->all(), [
'name' => 'min:2|max:35|string',
'surname' => 'min:2|max:35|string',
'email' => Sentinel::inRole('Admin')?'required|email|min:3|max:50|string':(Sentinel::check()?'required|email|min:3|max:50|string|unique:users,email,'.$id:'required|email|min:3|max:50|unique:users|string'),
'old_password' => 'min:6|max:50',
'new_password' => 'min:6|max:50',
]);
if ($update_user->fails()) {
return redirect()->back()
->withErrors($update_user)
->withInput();
}
$user = User::find($id);
if ($user) {
if(!empty($request->file('image'))){
$file = $request->file('image');
$destinationPath = public_path() . '/upload-client/profile_image';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$unwanted = array("\'", "+", "%");
$filename =str_replace($unwanted, "", $filename);
$uploadSuccess = $file->move($destinationPath, $filename);
$user->image_path=$filename;
}
if($request->name){
$user->name=$request->name;
}
if($request->email){
$user->email=$request->email;
}
if($request->old_password){
if (Hash::check($request->old_password, $user->password)){
$user->password=bcrypt($request->new_password);
}else{
Session::flash('message', 'Your old password is incorrect.');
Session::flash('status', 'error');
return redirect()->back()->withErrors(['old_password', 'your old password is incorrect']);
}
}
$user->update();
if ($request->role) {
$user->roles()->sync([$request->role]);
}
Session::flash('message', 'Success! User is updated successfully.');
Session::flash('status', 'success');
}
return redirect()->back();
}
感謝其工作@Alexey Mezenin –