i\'m trying to group my data by month and year.
$data ->select(DB::raw(\'count(id) as `data`\'),DB::raw(\'YEAR(created_at) year, MONTH(created_at) month\')
for latest version of mysql, the accepted answer will give error, so instead try
$data
->selectRaw("
count(id) AS data,
DATE_FORMAT(created_at, '%Y-%m') AS new_date,
YEAR(created_at) AS year,
MONTH(created_at) AS month
")
->groupBy('new_date')
->get();
ref: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format