Score:0

Laravel scope function for getting everyday data sum each day for a month or between 2 dates

in flag

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 avatar
in flag
I would like if someone Laravel expert review my Question not English expert.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.