在 laravel 中打印集合的值

LeB*_*eau 3 arrays debugging collections laravel-5

在我的控制器中,我有

$all = \App\Product::where('campaign_id', $product->campaign_id)->get();
Run Code Online (Sandbox Code Playgroud)

当我在模板中 DD 时

{{ dd($all)}}
Run Code Online (Sandbox Code Playgroud)

我得到一个集合对象

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 [?]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

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

kEp*_*pEx 5

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

您需要将 eloquent 模型转换为数组,以显示它

{{ dd($all->toArray()) }} 
Run Code Online (Sandbox Code Playgroud)

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