app/Services/DashboardServices.php
/***
     * Seven days of attendance data
     * @return \Illuminate\Support\Collection
     */
Seven days of attendance data
@return \Illuminate\Support\Collection
Seven days of attendance data @return \ Illuminate \ Support \ Collection
public static function sevenDaysAttendanceDataByDay()
    {
        $attendanceData = Attendance::query()
            ->where("attendance_date", ">", now()->subDays(7))
            ->join("accounts", "attendance.account_id", "=", "accounts.id")
            ->join("customers", "customers.id", "=", "accounts.contact_id")
            ->select(
                DB::raw("count(account_id) as counts"),
                DB::raw("DATE_FORMAT(attendance_date,'%d') as day"),
                DB::raw("gender as gender")
            )
            ->groupBy(["day", "gender"])
            ->orderBy("day") 
            ->get()
            ->toArray();
        $attendanceDataCollection = collect($attendanceData);
        return $attendanceDataCollection->mapToGroups(function ($item, $key) {
            return [
                "data" => [
                    "count" => $item["counts"],
                    "day" => $item["day"],
                    "gender" => $item["gender"],
                ],
            ];
        });
    }
public static function sevenDaysAttendanceDataByDay ( ) { $ attendanceData = Attendance :: query ( ) -> where ( " attendance_date " , " > " , now ( ) -> subDays ( 7 ) ) -> join ( " accounts " , " attendance.account_id " , " = " , " accounts.id " ) -> join ( " customers " , " customers.id " , " = " , " accounts.contact_id " ) -> select ( DB :: raw ( " count(account_id) as counts " ) , DB :: raw ( " DATE_FORMAT(attendance_date,'%d') as day " ) , DB :: raw ( " gender as gender " ) ) -> groupBy ( [ " day " , " gender " ] ) -> orderBy ( " day " ) -> get ( ) -> toArray ( ) ; $ attendanceDataCollection = collect ( $ attendanceData ) ; return $ attendanceDataCollection -> mapToGroups ( function ( $ item , $ key ) { return [ " data " => [ " count " => $ item [ " counts " ] , " day " => $ item [ " day " ] , " gender " => $ item [ " gender " ] , ] , ] ; } ) ; }
Seven days of attendance data
 @return \Illuminate\Support\Collection
Seven days of attendance data @return \ Illuminate \ Support \ Collection
// sort by day oldest day first