Php Laravel 5.4:将每个项目作为一个表格中的行插入

Php Laravel 5.4:将每个项目作为一个表格中的行插入,php,eloquent,laravel-5.4,Php,Eloquent,Laravel 5.4,我有一个表格,在这里插入多个产品这是我的表格 {!! Form::open(['route'=>'export-list.store']) !!} @foreach($orderis as $orderi) {!! Form::hidden('product_id[]', $orderi->productId->id) !!} {!! Form::hidden('quantity[]', $orderi->qua

我有一个表格,在这里插入多个产品这是我的表格

{!! Form::open(['route'=>'export-list.store']) !!}
        @foreach($orderis as $orderi)
           {!! Form::hidden('product_id[]', $orderi->productId->id) !!}
           {!! Form::hidden('quantity[]', $orderi->quantity) !!}
               <tr>
                  <td>{!! $sn++ !!}</td>
                  <td width="5%">
                  {!! Html::image('images/products/'. $orderi->productId->image, 'thumbs-'.$orderi->productId->name, ['height' => 70]) !!}
                  </td>
                  <td>{!! $orderi->product_name !!}</td>
                  <td>{!! $orderi->quantity !!}</td>
                  <td>
                     <div class="col-md-5">
                        <div class="form-group-inner">
                       {!! Form::text('inventory[]', null, ['class'=>'form-control']) !!}
                        </div>
                     </div>
                 </td>
                 <td>{!! $orderi->productId->price !!}</td>
                 <td>{!! $orderi->productId->price * $orderi->quantity !!}</td>
               </tr>
           @endforeach
               <tr>
                 <td colspan="9">{!! Form::submit('Submit', ['class'=>'btn btn-primary']) !!}</td>
               </tr>
{!! Form::close() !!}
这是我的控制器

public function store( Request $request ) {
        $input = $request->all();

        //Check for the needed quantity
        $quantity        = $input['quantity'];
        $inventory       = $input['inventory'];
        $needed_quantity = $quantity - $inventory;
        //Get the product information
        $productInfo = ( new Product() )->find( $input['product_id'] );
        $totalPrice  = $productInfo->price * $needed_quantity;


        ( new PurchaseOrder() )->create( [
            'product_id'      => $input['product_id'],
            'product_name'    => $productInfo->translate( 'ar' )->name,
            'product_image'   => $productInfo->image,
            'needed_quantity' => $needed_quantity,
            'unit_price'      => $productInfo->price,
            'total_price'     => $totalPrice,
            'barcode'         => $productInfo->barcode,
        ] );

        return redirect()->route( 'order-detail.index' )->with( 'status', 'Created successfully' );
    }

如何将每个项目作为行插入我的表格

非常感谢@SNAPEY帮助我解决问题

当我用不同的名称命名我的字段时会更容易。。。 作为

最终结果是这样的

array:2 [▼
  "_token" => "muw3phvtnjnJnjBYNqbp0A5f6Pk5St1BkydKPGG7"
  "products" => array:3 [▼
    0 => array:3 [▼
      "product_id" => "856"
      "quantity" => "9"
      "inventory" => "2"
    ]
    1 => array:3 [▼
      "product_id" => "857"
      "quantity" => "8"
      "inventory" => "3"
    ]
    2 => array:3 [▼
      "product_id" => "858"
      "quantity" => "2"
      "inventory" => "4"
    ]
  ]
]
$eachProducts = $input['products'];

foreach ( $eachProducts as $each_product ) {
    $quantity        = $each_product['quantity'];
    $inventory       = $each_product['inventory'];
    ......
}
使用
foreach
这样管理控制器中的数据非常容易

array:2 [▼
  "_token" => "muw3phvtnjnJnjBYNqbp0A5f6Pk5St1BkydKPGG7"
  "products" => array:3 [▼
    0 => array:3 [▼
      "product_id" => "856"
      "quantity" => "9"
      "inventory" => "2"
    ]
    1 => array:3 [▼
      "product_id" => "857"
      "quantity" => "8"
      "inventory" => "3"
    ]
    2 => array:3 [▼
      "product_id" => "858"
      "quantity" => "2"
      "inventory" => "4"
    ]
  ]
]
$eachProducts = $input['products'];

foreach ( $eachProducts as $each_product ) {
    $quantity        = $each_product['quantity'];
    $inventory       = $each_product['inventory'];
    ......
}