我有POST数据:
[{"id":1,"amount":0,"debit":10,"credit":0,"invoice":{"AC_code":"10","AC_name":"Qeyri-maddi aktivlər","AC_id":2}},
{"id":2,"amount":0,"debit":0,"credit":10,"invoice":{"AC_code":"18","AC_name":"Sair uzunmüddətli maliyyə aktivləri","AC_id":33}}]
我尝试这样迭代传入的数组:
public function update(Request $request, $id)
{
foreach($request as $k => $value) {
echo $value['amount']; // $value->amount
}
}
但是我收到错误消息:
{"errors":"Cannot use object of type Symfony\\Component\\HttpFoundation\\ParameterBag as array"}
答案 0 :(得分:2)
也许尝试一下:
public function update(Request $request, $id) {
foreach($request->all() as $key => $value) {
echo $value->amount;
}
}