php - Validation Radio Button Laravel 5.4

250

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 >
          <thead>
            <tr>
              @foreach($formasPago as $forma)
              <th><div >
                  <label for="formaPago" ></label>
                   <input type="radio"
                     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'
    ]); 
123

Answer

Solution:

Set name attribute for radio button

@foreach($formasPago as $forma)
            <th><div >
                <label for="formaPago" ></label>
                 <input type="radio" name="formaPago"
                   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); 

People are also looking for solutions to the problem: php - WooCommerce: Product Loop by Vendor?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.