'How I can get total sum of daily values of a column in Laravel?

There is an orders table with a total column that has more than 1000 records. How I can get the daily sum of total for each day. I mean for Monday, Thursday, Wednesday, .... there are many and different rows, and I want to show the sum of total of each day separately? in UI as:

saturday: 111211,
sunday: 211444,
Monday: 120012000,
Thursday: 1225121,

Friday sales



Solution 1:[1]

I use ORM and this worked for me:

        $sales = Order::all()->groupBy(function ($date) {
            return $date->created_at->format('Y-m-d');
        })->map(function ($item) {
            return [
              "date" => item[0]->created_at,
              "total" => $item->sum('total'),
            ];
        });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mehdi Yaghoubi