如何使用d($ request-> all())将数组数据保存到数据库中在拉拉韦尔

时间:2019-02-08 07:24:18

标签: php laravel

这是save()函数中的代码:

for($i=0; $i<= count($input['quantity_ordered']); $i++) {

       if(empty($input['quantity_ordered'][$i]) || !is_numeric($input['quantity_ordered'][$i])) continue;

       $data = [ 
         'order_no' => $input['order_no'][$i],
         'quantity_ordered' => intval($input['quantity_ordered'][$i])
       ];

        purch_order_verify_details::insert($data);
     }

这是 VIEW

              @foreach($invoiceData as $k=>$result)
                <tr class="tbl_header_color dynamicRows">
                  <input type="hidden" name="purchase_detail_id[]" value="{{$result->po_detail_item}}" />
                  <td width="10%" class="text-center"><input type="hidden" name="item_code[]" value="{{$result->item_code}}">{{$result->item_code}}</td>
                  <td width="30%" class="text-center hidden-sm hidden-xs"><input type="hidden" name="description[]" value="{{$result->description}}">{{$result->description}}</td>
                  <td width="10%" class="text-center"><input type="hidden" name="quantity_ordered[]" value="{{$result->quantity_ordered}}">{{$result->quantity_ordered}}</td>
                  <td><input class="form-control text-center no_units" stock-id="{{$result->quantity_ordered}}" min="0" data-id="{{$result->quantity_ordered}}" id="qty_{{$result->quantity_ordered}}" name="item_quantity[]" value="{{$result->quantity_ordered}}" data-tax="{{$result->quantity_ordered}}" type="text"><input name="item_id[]" value="{{$result->quantity_ordered}}" type="hidden"></td>
                </tr>
              @endforeach

1 个答案:

答案 0 :(得分:0)

我认为您的if语句缺少花括号

for($i=0; $i<= count($input['quantity_ordered']); $i++) {
    if (empty($input['quantity_ordered'][$i]) || !is_numeric($input['quantity_ordered'][$i])) {
        $data = [ 
            'order_no' => $input['order_no'][$i],
            'quantity_ordered' => intval($input['quantity_ordered'][$i])
        ];

     purch_order_verify_details::insert($data);
     }
}