SELECT COUNT(*) as count, MONTH(begin_date) FROM `events` WHERE (YEAR(begin_date) = YEAR(CURDATE())) OR (YEAR(begin_date) = YEAR(CURDATE()) + 1) GROUP BY MONTH(begin_date)
Here is sql query, i want to write it in laravel eloquent.
what i try:
$oncoming_events = DB::table('events') ->select(DB::raw('count(*) as numOfOncomingEvents, MONTH(begin_date)')) ->where('YEAR(begin_date)', '=', 'YEAR(CURDATE())') ->orWhere('YEAR(begin_date)', '=', 'YEAR(CURDATE()) +1') ->groupBy('MONTH(begin_date)')->get();
Error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'YEAR(begin_date)' in 'where clause' (SQL: select count(*) as numOfOncomingEvents, MONTH(begin_date) from
events
whereYEAR(begin_date)
=
laravel 5.6
btw sql query works..
whereYear('begin_date', date('Y'))
– RainDev