Collections also provide support for "higher order messages", which are short-cuts for performing common actions on collections. This example calculates the price per group of products on an offer.
1$offer = [ 2 'name' => 'offer1', 3 'lines' => [ 4 ['group' => 1, 'price' => 10], 5 ['group' => 1, 'price' => 20], 6 ['group' => 2, 'price' => 30], 7 ['group' => 2, 'price' => 40], 8 ['group' => 3, 'price' => 50], 9 ['group' => 3, 'price' => 60]10 ]11];12 13$totalPerGroup = collect($offer['lines'])->groupBy->group->map->sum('price');