简体   繁体   中英

Printing out values of a collection in laravel

In my controller I have

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

When I DD out in the template

{{ dd($all)}}

I get a collection object

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 [▶]
    }
  ]
}

How do I see the basic array returned?

I know this question is old, but can't believe is not answered.

You need to convert the eloquent model to an array, to display it

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

More info here: https://laravel.com/docs/5.6/eloquent-serialization

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM