我有一个销售产品表格,用户将在收银台收到针对产品的现金,产品可能很多。如何使用雄辩的查询生成器和以下数组模式一次提交该记录
Array
(
[_token] => jsVji1V6cTt5XmD2XgWyA7GEH5lvPlYbYWtUPIrt
[productId] => Array
(
[0] => 1
[1] => 2
)
[quantity] => Array
(
[0] => 1
[1] => 1
)
[amountReceived] => Array
(
[0] => 100
[1] => 500
)
[deliveryLocation] => Array
(
[0] => london
[1] => new york
)
)
答案 0 :(得分:0)
只需创建一个如下所示的关联数组并插入:
for($i=0;$i<count(data['productId']);$i++){
$temp[]=array('productId'=>$data['productId'][$i], 'Quantity'=>$data['Quantity'][$i],'amountReceived'=>$data['amountReceived'][$i]);
}
Model::insert($temp);