Inserting Cart Products into Multiple Tables Only Inserts the 1 latest product of 购物车

Inserting Cart Products into Multiple Tables Only Inserts the 1 latest product of cart

我想将购物车的内容插入到多个表中。它正在插入,但问题是它只从我的购物车中插入 1 件产品。但购物车的内容有 3 件商品。 我正在使用 Crinsane/LaravelShoppingCart.

如何将产品 A、B、C 插入到多个表中?

CartController@checkout

购物车中的商品

您需要在for循环中定义变量:

$transactions = [];
$transactions_solds = [];
$transactions_prods = [];


foreach(Cart::contents() as $c) {
$transaction = new Transaction();
$sold = new TransactionsSold();
$prod = new TransactionsProd();

// Rest of code

array_push($transactions, $transaction);
array_push($transactions_solds, $sold);
array_push($transactions_prods, $prod);
}