0

我知道有很多关于类似问题的问题,但我无法对我的问题应用任何解决方案。

我将 Laravel 与 Confide 一起使用,它使用 Ardent 进行验证。

我保存用户没有任何问题,密码确认在插入数据库时​​被删除(应该如此)并且用户被正确插入。

尝试更新用户时出现问题。如果我尝试验证用户,我会收到一条错误消息,指出用户不是唯一的:

public function storeProfile()
    {
        $user = $this->currentUser;
        $user->password = Input::get( 'password' );
        $user->password_confirmation = Input::get( 'password_confirmation' );
        //$user->updateUniques();
        $user->save();
        dd($user->errors()->all());

    }


string (31) "username is not unique"

string (28) "email is not unique"

如果我尝试使用 $user->updateUniques() (正如我在 SO 中的另一个问题中看到的那样作为可能的解决方案),它不会抱怨唯一性,而是抱怨密码确认不存在于数据库中(所以它不会删除它在插入之前)。

public function storeProfile()
    {
        $user = $this->currentUser;
        $user->password = Input::get( 'password' );
        $user->password_confirmation = Input::get( 'password_confirmation' );
        $user->updateUniques();
        dd($user->errors()->all());

    }

 Column not found: 1054 Unknown column 'password_confirmation' in 'field list' (SQL: update `users` set `password` = y$wyNl2xMNJqL0mY4X766EfOvO.IKICyDfXckS1cas1Psj1TLwpJZWu, `updated_at` = 2014-03-07 17:13:04, `password_confirmation` = 123456 where `id` = 1) 

我试过了

公共 $autoPurgeRedundantAttributes = true;

public $forceEntityHydrationFromInput = false;
public $autoHydrateEntityFromInput = false;

正如我在Laravel/Ardent/User 模型编辑 + 保存中看到的,但它也不起作用。在此先感谢您的帮助。

4

1 回答 1

0

好的,事实证明我收到错误的原因是因为我同时使用了 updateUniques() 和 save()。这有效:

public function storeProfile()
    {
        $user = $this->currentUser;
        $user->password = Input::get( 'password' );
        $user->password_confirmation = Input::get( 'password_confirmation' );
        $user->updateUniques();
        if ( !$user->errors()->all() ){
            return Redirect::action('UsuarioController@editProfile')
                ->with('success', 'Success!!');
        }
}
于 2014-03-10T10:06:38.527 回答