【发布时间】:2019-07-10 17:23:41
【问题描述】:
我正在尝试使 Laravel 中的默认注册表单适应我的数据库自定义用户表;我有一个不返回值的复选框,即使它被选中,它也不会返回值。验证器会在提交后提醒我复选框字段是必需的,即使我选择了它。
这是复选框:
<!--checkbox-->
<div class="form-group row">
<label for="usertype" class="col-md-4 col-form-label text-md-right">Type Utilisateur</label>
<div class="col-md-6">
<input type="checkbox" name="check[]" value="normal"/> Normal
<input type="checkbox" name="check[]" value="admin"/> Admin
<input type="checkbox" name="check[]" value="super"/> Super
@if ($errors->has('usertype'))
<span class="help-block">
<strong>{{ $errors->first('usertype') }}</strong>
</span>
@endif
</div>
</div>
编辑:验证器
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
'telephone' => ['required', 'numeric'],
'usertype' => ['required', 'string'],
]);
}
注意:我从验证中删除了用户类型,但注册不会继续,注册页面会刷新,不会出现错误或任何警报
【问题讨论】:
-
你能把你的验证码贴在这里吗?
-
@1000Nettles 已添加到问题中