0

How to get the scope function to get the sum of data of each day for a month or between 2 dates. I tried this but it did not work.

public function scopeEachDayInPeriod($query, array $dates){

    $period = CarbonPeriod::create($dates[0], $dates[1]);
    foreach ($period as  $date) {
     
        $day = $date->format('Y-m-d');
        $days30[] =$day;
        $kwh30days[] = Charge::whereDate('start', $day)->get()->sum('kWh');
     
        $query->where('start',$day);
    }
    return $query->whereDate('start', '>=', $dates[0])
    ->whereDate('start', '<=', $dates[1]);
}
babita
  • 1

0 Answers0