Laravel 5.1身份验证注册未获取数据


Laravel 5.1 Authentication registration not getting data

我一直在搜索,但找不到答案。拉拉维尔的文件有点含糊。

我正在尝试注册一个用户,在大多数情况下,它是使用Laravel的内置身份验证工具工作的。我所要做的就是,当用户注册时,我希望有一个first_name和last_name字段,而不是只有一个name字段。

为了做到这一点,我创建了一个迁移,它扩展了defualt-laravel迁移创建的users表。这是它的代码:


<?php
use Illuminate'Database'Schema'Blueprint;
use Illuminate'Database'Migrations'Migration;
class AddFirstNameLastNameToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::table('users', function($table) {
            $table->dropColumn('name');
            $table->string('first_name')->after('id');
            $table->string('last_name')->after('first_name');
        });
    }
    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::table('users', function($table) {
            $table->dropColumn('last_name');
            $table->dropColumn('first_name');
            $table->string('name');
        });
    }
}

在那之后,我创建了注册表的视图


@extends('../master')
@section('content')
    <div class="container">
        <div class="row">
            {!! Form::open(['url' => url('auth/register'), 'method' => 'post']) !!}
            <div class="form-group">
                {!! Form::label('email', 'Email') !!}
                {!! Form::email('email', null, ['class'=>'form-control', 'id'=>'username']) !!}
            </div>
            <div class="form-group">
                {!! Form::label('first_name', 'First Name') !!}
                {!! Form::text('first_name', null, ['class'=>'form-control']) !!}
            </div>
            <div class="form-group">
                {!! Form::label('last_name', 'Last Name') !!}
                {!! Form::text('last_name', null, ['class'=>'form-control']) !!}
            </div>
            <div class="form-group">
                {!! Form::label('password', 'Password') !!}
                {!! Form::password('password', ['class'=>'form-control']) !!}
            </div>
            <div class="form-group">
                {!! Form::label('password_confirmation', 'Password Confirmation') !!}
                {!! Form::password('password_confirmation', ['class'=>'form-control']) !!}
            </div>
            <div class="form-group">
                {!! Form::submit("Register") !!}
            </div>
            {!! Form::close() !!}
        </div>
    </div>
@stop

它说auth控制器中的validate函数将验证输入,所以下面是它的代码:


protected function validator(array $data)
{
    return Validator::make($data, [
        'first_name' => 'required|max:255',
        'last_name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
    ]);
}

现在,所有这些似乎都很好——问题出在auth控制器中的create函数中。auth方法接收一个数据数组,laravel 5.1文档没有说明这个数组中会有什么。我以为是注册表中的表单字段,但我没有得到注册表中的first_name和last_name字段。它必须正确验证,因为条目保存在数据库中,但first_name和last_name列没有保存。我对数据数组做了一个dd,但它并没有消亡,所以我不知道数组中有什么,也不知道如何在数组中获取信息。

附带说明,laravel文档也没有说明注册验证失败时错误将保存在哪里,所以我不知道如何显示注册错误。

编辑:

这是模型,first_name和last_name字段无法填写。然后,在@Andrew的建议下,我让它们可以填充,但它仍然没有填充字段。


<?php
namespace SellIt;
use Illuminate'Auth'Authenticatable;
use Illuminate'Database'Eloquent'Model;
use Illuminate'Auth'Passwords'CanResetPassword;
use Illuminate'Foundation'Auth'Access'Authorizable;
use Illuminate'Contracts'Auth'Authenticatable as AuthenticatableContract;
use Illuminate'Contracts'Auth'Access'Authorizable as AuthorizableContract;
use Illuminate'Contracts'Auth'CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
                                    AuthorizableContract,
                                    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['first_name', 'last_name', 'email', 'password'];
    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];
}

所以。。。有趣的故事。它在MySQL工作台中显示了一行,所以我会右键单击该行,点击delete,它会将表显示为空。事实证明MySQL Workbench实际上并没有删除该记录。我用一个查询手动删除了记录,然后再次注册,它就工作了。谢谢你们的帮助。