Laravel,更新密码,然后将旧密码保存在表格中

时间:2019-03-02 16:30:03

标签: php laravel laravel-5 eloquent

每个人,我需要在用户表的old_password中保存旧用户密码

我做到了

   protected function updatePassword( $user, Request $request)
{
    dd($user);
    $user = User::find( $user->id); // This will find the right user
    $user->old_password = $user->password; // This will save the old password
    $user->password = $request->password;
    $user->save();
}

我的路线

Route::post('/password/reset/{token}',  'Auth\ResetPasswordController@old_passwords');

但没有任何帮助

2 个答案:

答案 0 :(得分:1)

检查您的用户模型,它必须是这样的:

    protected $fillable = [
       'old_passwords'
        /*and your other fillable columns*/
    ];

答案 1 :(得分:1)

尝试一下:


protected function updatePassword($id, $password)
    {
       $user = User::find($id); // This will find the right user
       $user->old_password = $user->password; // This will save the old password
       $user->password = $password;
       $user->save();
    }

此功能将根据表格更新用户密码,然后将旧密码保存在old_password列中