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 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题