验证单选按钮Laravel 5.4

时间:2019-06-18 17:41:29

标签: php laravel

嗨,这很好奇,我不明白如何验证无线电输入,我已经使用laravel验证了其他输入,但是无线电没有。我当然是Laravel初学者。当我不填写框架时,请不要打印错误。因此,formaPago未通过验证。干杯。 这是HTML:

   <table class="table table-striped">
                    <thead>
                        <tr>
                            @foreach($formasPago as $forma)
                            <th><div class="form-check" >
                                    <label for="formaPago" class="form-check-label"></label>
                                     <input type="radio"
                                        class="form-check-input"  value="{{$forma->id}}"
                                        name="formaPago"   >{{$forma->nombre}}
                                </div></th> @endforeach
                        </tr>
                    </thead>

控制器中的验证器看起来是这样的:

  $validator = \Validator::make($request->all(), [
                'nombreCompleto'=> 'required|string|max:255',
                'email'=>  Session::has('clientePotencial')?'required|string|email|max:255':'required|string|email|max:255|unique:users',
                'celular'=> 'required',
                'cedula'=> 'required',
        'primaria'=> 'required',
        'secundaria'=> 'required',
        'referencia'=> 'required',
        'formaPago'=> 'required|filled'
    ]); 

1 个答案:

答案 0 :(得分:0)

设置单选按钮的名称属性

@foreach($formasPago as $forma)
                        <th><div class="form-check" >
                                <label for="formaPago" class="form-check-label"></label>
                                 <input type="radio" name="formaPago"
                                    class="form-check-input"  value="{{$forma->id}}"
                                    name="formaPago"   >{{$forma->nombre}}
                            </div></th> @endforeach

获取有效值列表并在验证中添加以下规则

$validValues = //....get value from db

'gander'=> 'required|in:'.implode(",",$validValues);