app/Http/Controllers/Statistics.php
/**
     * Sorts the items of the collection into groups by date.
     *
     * @param Collection $collection
     * @param string     $attribute
     * @param Carbon     $from
     * @param Carbon     $to
     * @param bool       $filterFirst   whether or not to filter by the attribute first
     *
     * @return array
     */
Sorts the items of the collection into groups by date.

@return array
Sorts the items of the collection into groups by date . @return array
public static function processCollectionItemsByDate(Collection $collection, string $attribute, Carbon $from, Carbon $to, bool $filterFirst = true): array
    {
        $start = clone $from;
        $data = [];
        $from = $from->startOfDay();
        $to = $to->endOfDay();
        while ($start->lessThanOrEqualTo($to)) {
            $key = $start->format('Y-m-d');
            $data[$key] = [];
            $start->addDay();
        }
        if ($filterFirst) {
            $collection = $collection->filter(function ($item) use ($from, $to, $attribute) {
                return $item->{$attribute}->greaterThanOrEqualTo($from) && $item->{$attribute}->lessThanOrEqualTo($to);
            });
        }
        foreach ($collection as $item) {
            $key = $item->{$attribute}->format('Y-m-d');
            if (empty($data[$key])) {
                $data[$key] = [];
            }
            $data[$key][] = $item;
        }
        return $data;
    }
public static function processCollectionItemsByDate ( Collection $ collection , string $ attribute , Carbon $ from , Carbon $ to , bool $ filterFirst = true ) : array { $ start = clone $ from ; $ data = [ ] ; $ from = $ from -> startOfDay ( ) ; $ to = $ to -> endOfDay ( ) ; while ( $ start -> lessThanOrEqualTo ( $ to ) ) { $ key = $ start -> format ( 'Y-m-d' ) ; $ data [ $ key ] = [ ] ; $ start -> addDay ( ) ; } if ( $ filterFirst ) { $ collection = $ collection -> filter ( function ( $ item ) use ( $ from , $ to , $ attribute ) { return $ item -> { $ attribute } -> greaterThanOrEqualTo ( $ from ) && $ item -> { $ attribute } -> lessThanOrEqualTo ( $ to ) ; } ) ; } foreach ( $ collection as $ item ) { $ key = $ item -> { $ attribute } -> format ( 'Y-m-d' ) ; if ( empty ( $ data [ $ key ] ) ) { $ data [ $ key ] = [ ] ; } $ data [ $ key ] [ ] = $ item ; } return $ data ; }
Sorts the items of the collection into groups by date.
Sorts the items of the collection into groups by date .
# get the data # the key