【问题标题】:Modifying default Laravel authentication修改默认 Laravel 身份验证
【发布时间】:2018-02-10 00:28:07
【问题描述】:

我使用

导入了 Laravel 身份验证

Php 工匠制作: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();
    });
}

如您所见,我已将用户类型添加到我认为需要添加的所有地方,我是否错过了某个地方?

【问题讨论】:

    标签: php laravel authentication laravel-artisan


    【解决方案1】:

    创建HTML 元素时,请求中发送的内容是值,这些值是keyed,每个字段上名为name 的属性,如您所见,您的选择缺失那个属性,试试:

    <select class="form-control" name="user-type">
    

    要对此进行测试,您可以在创建新用户之前将 dd($data); 放入 create 方法中

    【讨论】:

    • 救生员@Nikola。这么明显的错误
    猜你喜欢
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2016-09-07
    • 2020-03-20
    相关资源
    最近更新 更多