1$collection = collect([
2 ['account_id' => 'account-x10', 'product' => 'Chair'],
3 ['account_id' => 'account-x10', 'product' => 'Bookcase'],
4 ['account_id' => 'account-x11', 'product' => 'Desk'],
5]);
6
7$grouped = $collection->groupBy('account_id');
8
9$grouped->toArray();
10
11/*
12 [
13 'account-x10' => [
14 ['account_id' => 'account-x10', 'product' => 'Chair'],
15 ['account_id' => 'account-x10', 'product' => 'Bookcase'],
16 ],
17 'account-x11' => [
18 ['account_id' => 'account-x11', 'product' => 'Desk'],
19 ],
20 ]
21*/