1$collection = collect([1, 2, 3]);
2
3$collection->when(true, function ($collection) {
4 return $collection->push(4);
5});
6
7$collection->all();
8
9// [1, 2, 3, 4]
1$collection = collect([
2 ['product' => 'Desk', 'price' => 200],
3 ['product' => 'Chair', 'price' => 100],
4]);
5
6$collection->contains('product', 'Bookcase');
7
8// false
1$collection = collect([0, 1, 2, 3, 4, 5]);
2
3$chunk = $collection->take(3);
4
5$chunk->all();
6
7// [0, 1, 2]