dimanche 1 juillet 2018

laravel 5 : how to validate multi dimensional checkbox

Hello i have the following in my view

<table class="table">
   <tbody>
       @foreach($products as $indexKey => $product)
       <tr>
          <td>
             <input type="checkbox name="products[][id]" value=""/>
           </td>
           <td>
             <input type="text" name="products[][quantity]" value=""/>
          </td>
        </tr>
        @endforeach
   </tbody>
</table>

and in my controller

$this->validate($request,[
    'products'=>'required'
])

how can I validate that if one checkbox is checked, make sure the 'quantity' is not empty?

i checked so many websites and nothing comes close to my answer, they are all using just one dimensional array.

thank you!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire