修改默认的Laravel身份验证

时间:2018-02-09 16:22:47

标签: php laravel authentication artisan

我使用

导入了Laravels身份验证
  

Php artisan make:auth

我正在尝试在注册页面添加其他字段。新字段是一个下拉列表,有两个用户类型选项。业主/租户。当我点击注册时,我被重定向到登录脚本,我的所有细节仍然存在,并且注册尚未完成。其他地方可能存在问题,

我已经更新了我的模型并重新启动了它。我还将它添加到用户类的可填充数组中。

注册刀片模板   

                <div class="form-group row">
                  <label for="user-type" class="col-md-4 col-form-label text-md-right">User Type</label>
                    <div class="col-md-6">
                      <select class ="form-control" id="user-type">
                        <option>Landlord</option>
                        <option>Tenant</option>
                      </select>
                      @if ($errors->has('user-type'))
                          <span class="invalid-feedback">
                              <strong>{{ $errors->first('email') }}</strong>
                          </span>
                      @endif
                    </div>
                </div>

注册控制器

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

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'user-type' => $data['user-type']
    ]);
}

用户类

protected $fillable = [
        'name', 'email', 'password', 'user-type'
    ];

用户迁移

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('user-type');
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

正如您所看到的,我已将用户类型添加到我认为需要添加的所有位置,我是否遗漏了某个地方?

1 个答案:

答案 0 :(得分:0)

创建HTML元素时,请求中发送的内容是值,这些值在每个字段上由keyed属性name<select class="form-control" name="user-type"> ,当您可以看到你的选择缺少该属性,请尝试:

dd($data);

要对此进行测试,您可以在创建新用户之前将create置于{{1}}方法内