laravel push item to collection code example
Example 1: add to collection laravel
$item = collect();
$item->push($product);
Example 2: push collection php
$collection = collect([1, 2, 3, 4]);
$collection->push(5);
$collection->all();
// [1, 2, 3, 4, 5]
Example 3: laravel collection methods
$collection = collect([1,2,3,4]);
$collection->each(function($item){
return $item*$item;
});
// [1,4,9,16]