$collection = collect([
['name' => 'JavaScript: The Good Parts', 'pages' => 176, 'price' => 100.00],
['name' => 'JavaScript: The Definitive Guide', 'pages' => 314, 'price' => 150.00]
]);
$result = $collection->pipe(function ($collection) {
return collect([
'total_pages' => $collection->sum('pages'),
'total_price' => $collection->sum('price'),
]);
});
collect([1, 2, 3, 4, 5])->sum();
// 15