1

I have the following array and I would like to be able to organize it through collection

$collection =  Collection($total);
$filter = $collection->groupBy('date_general')->toArray();

[2017-11-14] => Array
    (
        [0] => Array
            (
                [status] => pending
                [date_general] => 2017-11-14
                [user_id] => 164
            )

        [1] => Array
            (
                [status] => pending
                [date_general] => 2017-11-14
                [user_id] => 112
            )
    )

Up to this point I already have the array organized by dates. Now within each date I need to organize it by user, that is to say that it is:

[2017-11-14] => Array
    (
        [164] => Array
            (
                [0] => Array
                    (
                        [status] => pending
                        [date_general] => 2017-11-14
                        [user_id] => 164
                    )
            )
        [112] => Array
            (
               [0] => Array
                (
                    [status] => pending
                    [date_general] => 2017-11-14
                    [user_id] => 112
                )
            )
    )
Oops D'oh
  • 941
  • 1
  • 15
  • 34

1 Answers1

4

You'll have to process each date group and individually group their contents.

$collection = collection($total)
    ->groupBy('date_general')
    ->map(function ($data) {
        return collection($data)->groupBy('user_id')->toArray();
    });

See also

ndm
  • 59,784
  • 9
  • 71
  • 110