0

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!

luis
  • 202
  • 5
  • 13

1 Answers1

0

Try this if it works

$this->validate($request,[
    'order_products'=>'required|array',
    'order_products.id' => 'required',
    'order_products.quantity' => 'required'
])
Wellwisher
  • 472
  • 2
  • 8
  • thank you @wellwisher but doesn't seems to work, i get error back even after all checkbox are clicked – luis Jul 02 '18 at 02:55
  • "the order products.product id is required, the order products.quantity is required" – luis Jul 02 '18 at 03:02
  • Take a look at [this](https://stackoverflow.com/questions/42258185/how-to-validate-array-in-laravel) – Zoran Jul 05 '18 at 21:10