Laravel grouping using the groupby(). How to return an array containing id?

Good day.
You have a query
$ret = User::select('id')->groupBy('age')->get();

Groups of rules have only the result arrays with user id:

Tell me how to do it. Thank you!
July 8th 19 at 16:13
2 answers
July 8th 19 at 16:15
$users = User::select(DB::raw('GROUP_CONCAT(id) as id'))->groupBy('age')->get();
$groups = $users->map(function ($item, $key) {
 return explode(',', $item['id']); // Possibly wrong here
Yes, there's a mistake. Not $groups = $users and $groups[] = $users . Differently did not work - amaya.Ruecker commented on July 8th 19 at 16:18
Thank you! - amaya.Ruecker commented on July 8th 19 at 16:21
July 8th 19 at 16:17
Something like this (spike):
$ret = User::select('id', 'age')->get()->groupBy('age')->map(function ($item) { return $item->pluck('id'); } )->toArray();

Find more questions by tags Laravel