doulang7699 2018-06-08 11:56
浏览 58
已采纳

无法将laravel数组传递给视图

I have an array that i want to return from the controller to the view.But unable to retrieve that. If i dump my array it looks like this:

array:121 [▼
  0 => array:10 [▼
    "ProcedureName" => "eye"
    "Status" => "referred"
    "PreferredDate" => "12/12/2018"
    "PreferredCity" => "Bangalore"
    "BookingId" => "EZBK000126"
    "Documents" => ""
    "Name" => "vik kon"
    "Age" => 62
    "Gender" => "male"
    "Mob" => "1110002223"
  ]
  1 => array:10 [▼
    "ProcedureName" => "eye"
    "Status" => "referred"
    "PreferredDate" => "12/12/2018"
    "PreferredCity" => "mysore"
    "BookingId" => "EZBK000125"
    "Documents" => ""
    "Name" => "vik kon"
    "Age" => 62
    "Gender" => "male"
    "Mob" => "9146178526"
  ]

So i want to get it to show inside my view .Currently my code looks like this :

@foreach($new_records as $new_recordss)

    <tr>

      <td scope="col">{{ $new_recordss->ProcedureName }}</td>

      <td scope="col">{{ $new_recordss->Status }}</td>

      <td scope="col">{{ $new_recordss->Age }}</td>

      <td scope="col"><div class="btn-group">

   </div>
 </td>


    </tr>
    @endforeach

But this gives the following error:

Trying to get property of non-object

  • 写回答

2条回答 默认 最新

  • duanpi7578 2018-06-08 12:00
    关注

    That's because an array is not an object.

    // -> is for object
    <td scope="col">{{ $new_recordss->ProcedureName }}</td>
    
    // [] is for array
     <td scope="col">{{ $new_recordss['ProcedureName'] }}</td>
    

    Thus this should work:

    <td scope="col">{{ $new_recordss['ProcedureName'] }}</td>
    <td scope="col">{{ $new_recordss['Status'] }}</td>
    <td scope="col">{{ $new_recordss['Age'] }}</td>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置