【问题标题】:Printing out values of a collection in laravel在 laravel 中打印出集合的值
【发布时间】:2017-12-19 08:33:54
【问题描述】:

在我的控制器中

$all = \App\Product::where('campaign_id', $product->campaign_id)->get();

当我在模板中 DD 时

{{ dd($all)}}

我得到一个集合对象

Collection {#340 ▼
  #items: array:1 [▼
    0 => Product {#341 ▼
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:10 [▶]
      #original: array:10 [▶]
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #events: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
  ]
}

如何查看返回的基本数组?

【问题讨论】:

    标签: arrays debugging laravel-5 collections


    【解决方案1】:

    我知道这个问题很老了,但不敢相信没有回答。

    需要将 eloquent 模型转换为数组,才能显示出来

    {{ dd($all->toArray()) }} 
    

    更多信息在这里:https://laravel.com/docs/5.6/eloquent-serialization

    【讨论】:

      猜你喜欢
      • 2014-09-11
      • 2010-09-17
      • 1970-01-01
      • 2019-09-01
      • 2020-01-25
      • 2018-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多