Reputation: 235
I am making a simple query request with a where condition. I need to have in this condition the year of a date field, in SQL i use "YEAR(date)=2015" In laravel when i use it, i get an error because he didnt find the column.
$total_num_rows_y = DB::table('insatisfaction')
->select(DB::raw('COUNT(id) as total_num_rows_y'))
->where('foo', $foo->id_aj)
->where('YEAR(date)', '2015')
->get();
Could you help me?
Upvotes: 0
Views: 1182
Reputation: 375
You can use whereYear
$total_num_rows_y = DB::table('insatisfaction')
->select(DB::raw('COUNT(id) as total_num_rows_y'))
->where('foo', $foo->id_aj)
->whereYear('date','=',2015)
->get();
Upvotes: 0
Reputation: 115
Let's try :
$total_num_rows_y = DB::table('insatisfaction')
->select(DB::raw('COUNT(id) as total_num_rows_y'))
->where('foo', $foo->id_aj)
->where(DB::raw('YEAR(start)'), '=', date('Y'));
->get();
Upvotes: 1