【问题标题】:laravel 5 : how to validate multi dimensional checkboxlaravel 5:如何验证多维复选框
【发布时间】:2018-07-03 04:50:08
【问题描述】:

你好,我有以下观点

<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>

在我的控制器中

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

如果选中一个复选框,我如何验证是否“数量”不为空?

我检查了很多网站,但没有一个能接近我的答案,它们都只使用一维数组。

谢谢!

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    如果可行就试试这个

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

    【讨论】:

    • 谢谢@wellwisher,但似乎不起作用,即使点击了所有复选框,我也会收到错误消息
    • "订单products.product id为必填,订单products.quantity为必填"
    • 看看this
    猜你喜欢
    • 2017-05-30
    • 2018-06-17
    • 2016-07-27
    • 2016-09-17
    • 2017-05-18
    • 1970-01-01
    • 2015-04-24
    • 2020-06-26
    • 1970-01-01
    相关资源
    最近更新 更多