在刀片中执行Foreach时接收非对象错误

问题描述 投票:0回答:1

在刀片中执行以下foreach时收到错误:

@foreach($updt_12 as $updt_12_qa)
<input type = "hidden" name = "id"  id="id" value="{{$updt_12_qa->qatype}}">

@endforeach

错误:

Trying to get property of non-object

qatype对于循环中的所有字段都是固定的,所以我如何使用此数组中的值,而不是仅仅为qatype从控制器发送变量而已?

dd($ update_12);

array:1 [▼
  0 => {#371 ▼
    +"id": 21
    +"created_at": "2019-10-17 13:21:22"
    +"updated_at": "2019-10-17 13:21:22"
    +"title": "q2"
    +"body": """
       \r\n
         ans 2
      """
    +"ttype": 0
    +"cat": 0
    +"a_id": 21
    +"tag": ""
    +"appr": 0
    +"user_id": 1
    +"comment_id": 0
    +"parent_id": null
    +"ppoints": null
    +"status": 0
    +"arank": 1
    +"qatype": 1
    +"country": "Egypt"
    +"wwide": 0
  }
]
php laravel
1个回答
0
投票

如果您将数组转换成数组,则可以这样使用。

@foreach($updt_12[0] as $updt_12_qa)
     <input type = "hidden" name = "id"  id="id" value="{{$updt_12_qa->qatype}}">
@endforeach
© www.soinside.com 2019 - 2024. All rights reserved.