【发布时间】:2021-12-30 08:02:44
【问题描述】:
我有很多记录需要在一个请求中进行编辑,所以我去了 POST 请求 尝试像这样编辑我的控制器中的数据:
foreach ($attr as $key){
foreach ($key->item as $attribute) {
if ($attribute['action'] == 'store') {
$insert_array = [
'subject_quiz_id' => $key->subject_quiz_id,
'registration_record_id' => $attribute->registration_record_id,
'mark' => $attribute->mark
];
}
} }
这是我的邮递员:
{
"subject_quiz_id": "7",
"item": [{
"action": "store",
"registration_record_id": "7",
"mark": "3"
},
{
"action": "store",
"registration_record_id": "7",
"mark": "3"
}]}
但它只是继续推送此错误:
"message": "Trying to get property 'item' of non-object",
"exception": "ErrorException",
【问题讨论】:
-
确保 $attr 是对象的数组/集合!
标签: php json laravel postman nested-loops