$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(['name' => 'taylor', 'framework' => 'laravel']);
$value = $collection->get('name');
// taylor
$collection = collect([1,2,3,4]);
$collection->each(function($item){
return $item*$item;
});
// [1,4,9,16]
$collection = collect([0, 1, 2, 3, 4, 5]);
$chunk = $collection->take(3);
$chunk->all();
// [0, 1, 2]
$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]
$users = $users->only([1, 2, 3]);
get(); //return collection
first(); //return object
$collection->each(function ($item, $key) {
hj
});