0

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.

totymedli
  • 29,531
  • 22
  • 131
  • 165
Pathsofdesign
  • 4,678
  • 5
  • 18
  • 26

2 Answers2

1

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.

deefour
  • 34,974
  • 7
  • 97
  • 90
  • 1
    Thank you for the answer. You're right about the changed method not even being part of the Ardent package. I think it's kind of weird how the author doesn't make that clear... I found that Ardent does come with an automatic password hash. [$autoHashPasswordAttributes](https://github.com/laravelbook/ardent#secure) – Pathsofdesign Jun 07 '13 at 03:21
1

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

Pathsofdesign
  • 4,678
  • 5
  • 18
  • 26