我正在使用 ardent 来验证我的 User 模型,但由于某种原因,它总是返回以下两个错误:
- 密码确认不匹配。
- 密码确认字段是必需的。
我已经被难倒了一段时间,所以任何帮助表示赞赏。猜测它与我的设置或 Ardent 有关,但无法弄清楚。我的单元测试通过了以下测试路线也通过了:
Route::get('testuser', function() {
$user = new User;
$user->first_name = 'John';
$user->last_name = 'Doe';
$user->birthday = '11/11/11/';
$user->email = 'johndoe@gmail.com';
$user->password = 'password';
$user->password_confirmation = 'password';
var_dump($user->save());
});
我不是在表单提交时以这种方式创建用户。我的控制器操作如下所示:
$user = $this->user->create(Input::all());
if ($user->save()) {
return Redirect::route('users.index')
->with('flash', 'The new user has been created');
}
return Redirect::route('register.index')
->withInput()
->withErrors($user->errors());
与 Input::all() 数组相等:
array (
'_token' => 'removed',
'first_name' => 'John',
'last_name' => 'Doe',
'birthday' => '11/11/11',
'email' => 'johndoe@gmail.com',
'password' => 'password',
'password_confirmation' => 'password',
)
最后我的用户模型是这样设置的:
class User extends Ardent implements UserInterface, RemindableInterface {
protected $table = 'users';
protected $hidden = array();
protected $fillable = array(
'email',
'first_name',
'last_name',
'birthday',
'password',
'password_confirmation'
);
protected $guarded = array('id');
public static $passwordAttributes = array('password');
public $autoPurgeRedundantAttributes = true;
public $autoHydrateEntityFromInput = false;
public static $rules = array(
'email' => 'required|email|unique:users',
'first_name' => 'required',
'last_name' => 'required',
'birthday' => 'required',
'password' => 'required|alpha_num|min:6|confirmed',
'password_confirmation' => 'required|alpha_num|min:8',
);