在laravel 5.8中的foreach循环中存储数据

问题描述 投票:0回答:2

在存储数据时,我需要您的帮助。

我有几个产品的购物车,现在我想通过单击提交按钮将所有这些产品同时存储在Order表中

我的视图blade.php

此视图显示购物车中的所有产品,我需要将这些信息存储在Order表中>

<form action="{{route('order.store')}}" method="post">
  @csrf
  @foreach ($cart as $ct)

  <input type="text" name="product_id" value="{{$ct->id}}" hidden>

  <input type="text" value="{{$ct->color}}" name="color" >

  <input type="text" value="{{$ct->size}}" name="size" >

  <input type="text" value="{{$ct->price}}" name="price" >

  @endforeach
 <button type="submit">submit</button>            
</form>

在我的Order表中,我需要填写以下4列:product_id,颜色,大小和价格。

我的foreach循环从Cart表中获取数据,并且所有数据均显示无误。

我的问题是,如何仅通过单击一次提交按钮就可以将这些数据存储到Order表中?我应该在store functionOrderController中写些什么?

如果我的购物车有3种产品,那么我的期望值是Order表将如下所示:

id----product_id----size----color---price---+
---------------------------------------------
1      1             abc     xyz     123
---------------------------------------------
2      2             abc2    xyz2    456
---------------------------------------------
3      3             aaa     bbb     789

感谢您的帮助!

我在数据存储方面需要您的帮助。我有几个产品的购物车,现在我想通过单击“提交”按钮将所有这些产品同时存储在“订单”表中。我的视图...

php mysql laravel-5.8
2个回答
2
投票

1
投票
© www.soinside.com 2019 - 2024. All rights reserved.