문제

I'm running though the Laravel 4 Ardent package found here: https://github.com/laravelbook/ardent

I'm trying to integrate the code found in Ardent's README within my User Model:

public function beforeSave( $forced )
{
    // if there's a new password, hash it
    if($this->changed('password'))
    {
        $this->password = Hash::make($this->password);
    }

    return true;
}

My User Model Test:

public function testSetPassword() 
{
    // Create a new User
    $user = new User;
    $user->email = "joe@smalls.com";
    $user->password = "password";
    $user->password_confirmation = "password";
    $user->save();

    /* Test #1 - Test to make sure password is being hashed */
    $this->assertTrue(Hash::check('password', $user->password), "the set_password() function did not return TRUE");
}

When I test via PhpUnit, it is telling me that '$this->changed()' is undefined.

BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::changed()

I'm basically trying to do as the tutorial says, and check to make sure the password has changed before saving it to the DB. Any help would be greatly appreciated.

도움이 되었습니까?

해결책 2

It doesn't appear that Ardent has a 'changed()' method as described in it's documentation. There is a boolean variable you can set to automatically HASH the password on save().

Automatically Transform Secure-Text Attributes

다른 팁

I don't use Ardent, but this can be done through Laravel directly with isDirty

if ($this->isDirty('password')) {
  //...
}

I don't see any changed method (or it being some pseudo-method picked up by __call) anywhere.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top