Laravel 5.2 在寄存器中添加条款和条件

Ace*_*Ace 5 php laravel laravel-5

我想在我的注册表验证表单中添加条款和条件,但它不起作用。有人可以帮我弄这个吗。

看法

<div class="form-group{{ $errors->has('terms') ? ' has-error' : '' }}">
  <label>
    <input type="checkbox" class="form-control" name="terms" value="{{ old('terms') }}" /> Agree with the terms and conditions
  </label>

  <div class="col-md-4">
    @if ($errors->has('terms'))
     <span class="help-block">
       <strong>{{ $errors->first('terms') }}</strong>
     </span>
    @endif
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

认证控制器

protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'company' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'telephone' => 'required|max:255',
            'password' => 'required|min:6|confirmed',
            'g-recaptcha-response' => 'required|captcha',
            'terms' => 'required'
          ]);

    }
Run Code Online (Sandbox Code Playgroud)

May*_*eyz 5

更改以下行:

<input type="checkbox" class="form-control" name="terms" value="{{ old('terms') }}" /> Agree with the terms and conditions
Run Code Online (Sandbox Code Playgroud)

<input type="checkbox" class="form-control" name="terms" value="1" /> Agree with the terms and conditions
Run Code Online (Sandbox Code Playgroud)

因为我们维护文本框、文本区域等的旧值,以防输入的旧值未通过验证,但在您的情况下,复选框需要静态值,即 1 或任何值。如果未选择,则会显示错误,但其值保持不变。