Hey!
I ended up with this
'graph' => $website->loadCount([
'reviews as firstMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(12), Carbon::now()]);
},
'reviews as secondMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(11), Carbon::now()]);
},
'reviews as thirdMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(10), Carbon::now()]);
},
'reviews as fourthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(9), Carbon::now()]);
},
'reviews as fifthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(8), Carbon::now()]);
},
'reviews as sixthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(7), Carbon::now()]);
},
'reviews as seventhMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(6), Carbon::now()]);
},
'reviews as eighthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(5), Carbon::now()]);
},
'reviews as ninthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(4), Carbon::now()]);
},
'reviews as tenthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(3), Carbon::now()]);
},
'reviews as eleventhMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(2), Carbon::now()]);
},
'reviews as twelfthMonth' => function ($query) {
$query->whereBetween('created_at', [Carbon::now()->subMonths(1), Carbon::now()]);
},
])
but its not working properly. I'm getting as results:
"firstMonth" => 2
"secondMonth" => 2
"thirdMonth" => 2
"fourthMonth" => 2
"fifthMonth" => 2
"sixthMonth" => 2
"seventhMonth" => 2
"eighthMonth" => 2
"ninthMonth" => 2
"tenthMonth" => 2
"eleventhMonth" => 2
"twelfthMonth" => 2
which isn't correct. This website have total of 2 reviews and they are written literally now (for test purposes). Any idea what's wrong?