Support the ongoing development of Laravel.io →
posted 2 years ago
Laravel
Last updated by @tvbeek 2 years ago.
0
moderator

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

3

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.