热心的password_confirmation错误

时间:2014-03-13 03:47:23

标签: php laravel ardent

我正在使用ardent来验证我的用户模型,但由于某种原因,它总是返回以下两个错误:

  • 密码确认不符。
  • 需要密码确认字段。

我已经被遗忘了一段时间,所以任何帮助都表示赞赏。猜测它与我的设置或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',
    );

0 个答案:

没有答案