虽然我在这里找到了Laravel 4 Ardent包: https://github.com/laravelbook/ardent
我正在尝试在我的用户模型中集成Ardent的README中的代码:
public function beforeSave( $forced )
{
// if there's a new password, hash it
if($this->changed('password'))
{
$this->password = Hash::make($this->password);
}
return true;
}
我的用户模型测试:
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");
}
当我通过PhpUnit进行测试时,它告诉我'$ this-> changed()'未定义。
BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::changed()
我基本上是按照教程所说的那样尝试,并检查以确保密码已更改,然后再将其保存到数据库中。任何帮助将不胜感激。
答案 0 :(得分:1)
我不使用Ardent,但这可以通过Laravel直接使用isDirty
if ($this->isDirty('password')) {
//...
}
我没有看到任何改变的方法(或者是__call
选择的一些伪方法)。
答案 1 :(得分:1)
Ardent似乎没有'{(3}}中描述的'changed()'方法。有一个布尔变量可以设置为在save()上自动HASH密码。