我正试图一次保存多个记录。
当我尝试存储多条记录时,它给出了数组到字符串转换的错误。
这是我从axios得到的响应。
array:2 [
0 => array:3 [
"property_type_id" => 2
"fee_value" => "123"
"product_service_id" => 1
]
1 => array:3 [
"property_type_id" => 1
"fee_value" => "3333"
"product_service_id" => 1
]
]
$feeByPropertyType = $request->feeByPropertyType;
foreach ($feeByPropertyType as $row)
{
$data[] = [
'property_type_id' => $row['property_type_id'],
'fee_value' => $row['fee_value'],
'product_service_id' => 1
];
}
PaymentTypeProductService::insert($data);
我也尝试了其他几种方法,但到目前为止都没有奏效。
我们将非常感谢社区提供的有关如何更正此问题的帮助。
答案 0 :(得分:0)
您需要格式化$data
才能如此。
[
[
'property_type_id' => 2,
'fee_amount' => "123"
],
[
'property_type_id' => 1,
'fee_amount' => "1312"
],
]
答案 1 :(得分:0)
在这种情况下,如果$request->feeByPropertyType
数据结构的数据结构与数据库表结构匹配,那么您可以简单地使用DB
门面一次插入多行。
DB::insert($request->feeByPropertyType);