简体   繁体   中英

Validation Radio Button Laravel 5.4

Hi this is courious I dont understand how I can validate a radio input, I have validated other inputs with laravel, but Radio no. Of course I am Laravel Beginner. When I don't filled the framework not give error to print. So formaPago is not validated. Cheers. This is the 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>

And the Validator in controller looks this way:

  $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'
    ]); 

Set name attribute for radio button

@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

get list of valid values and add below rule in validation

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM