Authentication Laravel 4密码确认不';好像没有按我所期望的那样工作

Authentication Laravel 4密码确认不';好像没有按我所期望的那样工作,authentication,laravel-4,passwords,eloquent,Authentication,Laravel 4,Passwords,Eloquent,我的代码来自Laracasts.com上的一段视频。我的想法是,我可以使用该验证方法创建一个用户。当我尝试确认密码时,无论发生什么,它似乎都不匹配。我最初的想法是,它是在验证之前对密码进行哈希运算,这会导致密码无论如何返回false 这是我到目前为止的所有代码 用户模型 protected $fillable = ['username' ,'email', 'password']; public static $rules = [ 'username' => 'requi

我的代码来自Laracasts.com上的一段视频。我的想法是,我可以使用该验证方法创建一个用户。当我尝试确认密码时,无论发生什么,它似乎都不匹配。我最初的想法是,它是在验证之前对密码进行哈希运算,这会导致密码无论如何返回false

这是我到目前为止的所有代码

用户模型

protected $fillable = ['username' ,'email', 'password'];

public static $rules = [
        'username' => 'required', 
        'email' => 'required|email', 
        'password' => 'required|confirmed'
];

public function isValid()
{
    $validation = Validator::make($this->attributes, static::$rules);

    if ($validation->passes()) return true;

    $this->errors = $validation->messages();
    return false;
}
UsersController@Store

public function store()
{
    $input = Input::all();

    if (! $this->user->fill($input)->isValid()) 
    { 
        return Redirect::back()->withInput()->withErrors($this->user->errors);
    }

    //if the user input is  valid then save it and assign associated role
    $this->user->save();
    $this->user->assignRole(Input::get('role'));

    return Redirect::to('/user')->with('flash_message', 'User added to the database!');
}
创建用户视图-表单

    {{ Form::open(['role' => 'form', 'route' => 'user.store']) }}
        <div class='form-group'>
            {{ Form::label('username', 'First Name') }}
            {{ Form::text('username', null, ['placeholder' => 'First Name', 'class' => 'form-control']) }}
        </div>
        <div class='form-group'>
            {{ Form::label('email', 'Email') }}
            {{ Form::text('email', null, ['placeholder' => 'Last Name', 'class' => 'form-control']) }}
        </div>
        <div class='form-group'>
            {{ Form::label('role', 'Role') }}
            {{ Form::select('role', $roles, "member", ['class' => 'form-control']) }}
        </div>
        <div class='form-group'>
            {{ Form::label('password', 'Password') }}
            {{ Form::password('password',  ['placeholder' => 'Password', 'class' => 'form-control']) }}
        </div>
        <div class='form-group'>
            {{ Form::label('password_confirmation', 'Password Confirm') }}
            {{ Form::password('password_confirmation',  ['placeholder' => 'Password Confirm', 'class' => 'form-control']) }}
        </div>
        <div class='form-group'>
            {{ Form::submit('Create User', ['class' => 'btn btn-primary']) }}
        </div>
        {{ Form::close() }}
{{Form::open(['role'=>'Form','route'=>'user.store'])}
{{Form::label('username','First Name')}
{{Form::text('username',null,['placeholder'=>'First Name','class'=>'Form control'])}
{{Form::label('email','email')}
{{Form::text('email',null,['placeholder'=>'Last Name','class'=>'Form control'])}}
{{Form::label('role','role')}
{{Form::select('role',$roles,'member',['class'=>'Form control'])}
{{Form::label('password','password')}
{{Form::password('password',['placeholder'=>'password','class'=>'Form control'])}
{{Form::label('password_confirmation','password confirmation')}
{{Form::password('password_confirmation',['placeholder'=>'password confirmation','class'=>'Form control'])}
{{Form::submit('Create User',['class'=>'btn btn primary'])}
{{Form::close()}}

发生的情况是,无论您输入什么,您的
密码确认
字段始终为空

这是因为您正在
存储
方法中使用
$This->user->fill($input)
。但是,在您的模型中

protected $fillable = ['username' ,'email', 'password']; 
因此,这将永远不会填充
密码确认
字段

如果将
filleble
更改为以下内容,则应该没有问题

protected $fillable = ['username' ,'email', 'password', 'password_confirmation'];

谢谢你的回复!我认为,当我向可填充字段添加password_confirmation时,我得到一个错误,指出该列在DB中不存在。SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“密码确认”(SQL:插入
用户
用户名
电子邮件
密码
密码确认
更新时间
创建时间
)值(测试test@gmail.com,password,password,2014-08-15 13:54:332014-08-15 13:54:33)我是否应该将其添加到数据库中,尽管这样做似乎不正确?不,这不是一个好主意。您可以执行以下操作:在控制器中,就在
$this->user->save()之前
取消设置该变量,以便ORM不必在数据库中查找该变量。您可以使用
取消设置($this->user->password\u confirmation);
取消设置该变量。非常感谢您的帮助。我不确定是否允许我升级投票,但如果可以,我会的!