add to collection laravel

46

Adding data to a laravel collection -

$items->put('products', $product);

push collection php -

$collection = collect([1, 2, 3, 4]);

$collection->push(5);

$collection->all();

// [1, 2, 3, 4, 5]

laravel collection methods -

$collection = collect([1,2,3,4]);

$collection->each(function($item){
    return $item*$item;
});

// [1,4,9,16]

Comments

Submit
0 Comments