我正在尝试保存订单,以及订单中的产品.
订单正在保存,但产品不是.
我有一张orders桌子,一张products桌子和一张orders_products桌子.
在我订的订单模型中 $hasAndBelongsToMany = 'Product';
在orders_products表我有几个额外的字段:order_id,product_id加price,quantity捕捉销售价格和销售数量.
我通过以下方式保存数据:
$这 - >命令中─>白水回收($数据);
以下是$ data的数据:
Array
(
[Order] => Array
(
[user_email] => st@kr.com
[billing_first] => Steve
... //more excluded
[total] => 5000
)
[Product] => Array
(
[0] => Array
(
[id] => 1
[price] => 5000.00
[quantity] => 1
)
)
)
Run Code Online (Sandbox Code Playgroud)
订单会保存到订单表中,但不会将任何内容保存到orders_products表中.我期望orders_products表保存[new_order_id], 1, 5000.00, 1
我收到了这个通知:
Notice (8): Undefined index: id …Run Code Online (Sandbox Code Playgroud)