Update laravel 5 profile password

I work in laravel 5.1 and my update profile works, but will not be encrypted and will not work now. When I try to update the user table, there will also be a password_confirmation field and there will be a conflict in the database. I do not understand. The form says successfully, but the database does not update

code

public function updatePassword() {
    $passwordData = Input::except('_token');
    $validation = Validator::make($passwordData, User::$passwordData);
    if ($validation->passes()) {
        array_forget($passwordData,'password_confirmation');
        User::where(array(
                'password' => Hash::make(Input::get('password'))
            ));
        Session::flash('password', 'Perfil editado com sucesso');
        return Redirect::to('backend/perfil/password');
    } else {
        return Redirect::to('backend/perfil/password')->withInput()->withErrors($validation);
    }   
}   

user

public static $passwordData = array(
        'password'              => 'required|confirmed',
        'password_confirmation' => 'required'
        );
+1
source share
1 answer

Follow these simple steps to get rid of anything.

Step 1: Get the password from the form

$PasswordData = Input::all();

Step 2: Confirm Your Password

Validator::extend('pwdvalidation', function($field, $value, $parameters) {
            return Hash::check($value, Auth::user()->password);
        });

Step 3: Define the validation rule in UserModel

public static $rulespwd = array('OldPassword' => 'required|pwdvalidation',
        'NewPassword' => 'required|confirmed|alphaNum|min:5|max:10',
        'NewPassword_confirmation' => 'required',
        );

Note :

4:. , else,

$validator = Validator::make($PasswordData, User::$rulespwd, $messages);
        if ($validator->passes()) {
            $user = User::find(Auth::user()->id);
            $user->password = Input::get('NewPassword');
            $user->save();
            return Redirect::to(Session::get('urlpath') . '/changepassword')->withInput()->with('Messages', 'The Password Information was Updated');
        } else {
            return Redirect::to(Session::get('urlpath') . '/changepassword')->withInput()->withErrors($validator);
        }
+1

Source: https://habr.com/ru/post/1615927/


All Articles