add to collection laravel
snippet in php

add to collection laravel

user766

$item = collect();
$item->push($product);

laravel collection methods

user1588

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

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

// [1,4,9,16]

pluck laravel

user6471

$name = DB::table('users')->where('name', 'John')->pluck('name');

push collection php

user6846

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

$collection->push(5);

$collection->all();

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