A collection of talented Laravel craftsmen

I run a query that returns a collection array with 7 elements -

$uniques = Analytics::fetchviews(Period::days(7))->take(7); 

The results of the collection look like this:

  2 => array:4 [▼ "date" => Carbon {#247 ▶} "uniquePageviews" => 1 "pageViews" => 1 ] 

I would like to take out pageViews and uniquePageviews and work with these integers before passing the results to the view. How can I directly edit data in a collection?

+5
source share
1 answer

A collection is just a list of models. You can iterate over them, work with your attributes, etc. For instance:

 foreach ($uniques as $unique) { var_dump($unique->pageViews); } 
+3
source

All Articles