月別チェックイン回数グラフ

This commit is contained in:
shibafu
2018-01-04 14:50:14 +09:00
parent bd19018699
commit c04ec89c3e
2 changed files with 67 additions and 1 deletions

View File

@@ -63,7 +63,28 @@ SQL
$calendarData[$timestamp] = $data->count;
}
return view('user.stats')->with(compact('user', 'calendarData'));
$groupByMonth = Ejaculation::select(DB::raw(<<<'SQL'
to_char(ejaculated_date, 'YYYY/MM') AS "date",
count(*) AS "count"
SQL
))
->where('user_id', $user->id)
->where('ejaculated_date', '>=', Carbon::now()->addMonths(-11)->firstOfMonth())
->groupBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM')"))
->orderBy(DB::raw("to_char(ejaculated_date, 'YYYY/MM')"))
->get();
$monthlyCounts = [];
$month = (new Carbon())->subMonth(11);
while ($month->format('Y/m') <= date('Y/m')) {
if ($groupByMonth->first()['date'] === $month->format('Y/m')) {
$monthlyCounts[] = $groupByMonth->shift()['count'];
} else {
$monthlyCounts[] = 0;
}
$month = $month->addMonth(1);
}
return view('user.stats')->with(compact('user', 'calendarData', 'monthlyCounts'));
}
public function okazu($name)