Hello @bumbar
I think is the solution you want have.
$orders = collect([
['id' => 33, 'OrderNumber' => 505, 'user_id' => 55],
['id' => 22, 'OrderNumber' => 505, 'user_id' => 152],
['id' => 20, 'OrderNumber' => 505, 'user_id' => 130],
['id' => 96, 'OrderNumber' => 494, 'user_id' => 209],
['id' => 95, 'OrderNumber' => 494, 'user_id' => 67],
['id' => 91, 'OrderNumber' => 492, 'user_id' => 234],
['id' => 86, 'OrderNumber' => 492, 'user_id' => 195],
]);
$results = $orders->groupBy(['OrderNumber'])
->map(static function(Collection $group): Collection {
return $group->skip(1);
})->flatten(1)
;
$results->dump();
Ps. I have updated your post to get the code blocks more readable.
bumbar, abubakarali129, samdanip liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community