I am using Laravel 8 and i want to get data of each month of the year. For example
month1 => 12
month2 => 14 so on ...
I have code
$invoices = Auth::user()->invoices()
->select(DB::raw('YEAR(invoice_date) year'), DB::raw('MONTH(invoice_date) month'), DB::raw('count(id) as `data`'))
->groupBy('year','month')
->get()->toArray();
it return following,
array:2 [▼
1 => array:3 [▼
"year" => 2021
"month" => 1
"data" => 6
]
2 => array:3 [▼
"year" => 2021
"month" => 2
"data" => 4
]]
but i have record in database 20. mean for month 1 record are 12 and for month 2 record are 8 but i get different.
Kindly help me where is i am wrong.
Table structure is