count total data created monthly
I tried using this query on postgress is shows the exact expected output
SELECT
extract(year from created_at) as year,
TO_CHAR( TO_TIMESTAMP (extract(month from created_at)::text, 'MM'), 'Month') as month,
COUNT(id) AS count
FROM project_areas
GROUP BY year, month
ORDER BY year, month
I tried using this code in laravel bt failed
return DB::table('project_areas')->select(DB::raw("extract(year from created_at) as year,
TO_CHAR( TO_TIMESTAMP (extract(month from created_at)::text, 'MM'), 'Month') as month,
COUNT(id) AS count"))
->groupBy('created_at')
->orderBy('created_at')
->get();