laravel 5 : how to validate multi dimensional checkbox

Multi tool use
Multi tool use


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="order_products[{{$indexKey}}][id]" value="{{$product->id}}"/>
</td>
<td>
<input type="text" name="order_products[{{$indexKey}}][quantity]" value=""/>
</td>
</tr>
@endforeach
</tbody>
</table>



and in my controller


$this->validate($request,[
'order_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!




1 Answer
1



Try this if it works


$this->validate($request,[
'order_products'=>'required|array',
'order_products.id' => 'required',
'order_products.quantity' => 'required'
])





thank you @wellwisher but doesn't seems to work, i get error back even after all checkbox are clicked
– luis
Jul 2 at 2:55





What errors are you getting?
– Wellwisher
Jul 2 at 2:58





"the order products.product id is required, the order products.quantity is required"
– luis
Jul 2 at 3:02






Take a look at this
– Zoran
2 days ago






so you have solved ?
– Wellwisher
yesterday






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

EkcbYN7,joLeF5pbGeBmFjXUX,ky2zu3aKEqL1m kVcVqJ9DmGLmIp ag2Z5LoM,1hdv4IY4pUKYl,o,Ukt,IKD9an,hEDU
vl,A0IC,pG44,2GebH,SCMq4H,lx58o,y eNeRc6

Popular posts from this blog

Rothschild family

Boo (programming language)