$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
// false
$collection = collect([1, 2, 3]);
$collection->when(true, function ($collection) {
return $collection->push(4);
});
$collection->all();
// [1, 2, 3, 4]
$collection = collect([1,2,3,4]);
$collection->each(function($item){
return $item*$item;
});
// [1,4,9,16]
$collection = collect(['taylor', 'abigail', null])->map(function($name)
{
return strtoupper($name);
})
->reject(function($name)
{
return empty($name);
});
collect([1, 2, 3])->all();
// [1, 2, 3]
get(); //return collection
first(); //return object
$collection->each(function ($item, $key) {
hj
});