I have a table having record_date
and corresponding amount
field.I was trying to retrieve total amount grouping by the months of the date .
I a
You need a raw
query and you may try this (Not tested but should work):
$data = DB::table('table_name')
->select(DB::raw('MONTH(record_date) as m, YEAR(record_date) as y, SUM(amount) as t'))
->whereRaw('record_date > DATE_SUB(now(), INTERVAL 6 MONTH)')
->groupBy(DB::raw('YEAR(record_date), MONTH(created_at)'))
->get();