doulang7699 2018-06-08 11:56 采纳率: 0%
浏览 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 鼠标右键,撤销删除 复制 移动,要怎样删除
  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术
  • ¥15 DockerSwarm跨节点无法访问问题