I am trying to execute the following query in Eloquent ORM and cannot seem to execute the MySQL function -
$post = Post::where('slug', '=', $slug)->where('YEAR(created_at)', '=', $year)->first();
The exception I am getting is as follows - Message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'YEAR(created_at)' in 'where clause'
SQL: SELECT * FROM `posts` WHERE `slug` = ? AND `YEAR(created_at)` = ? LIMIT 1
Bindings: array (
0 => 'placeholder',
1 => 2013,
)
So, basically, it is encapsulating the YEAR()
MySQL function as a column. Is there any way to do this without using a raw query?