Laravel 4 - group by and search by MySQL YEAR()
laravel-4, mysql, php
Solution
You are looking for DB::raw(). I think the following should work.
$thisYear = test::where('id', '=', $id)
->where(DB::raw('YEAR(start)'), '=', date('Y'));
Problem
I have a problem in a query I'am making in Laravel. My query looks like this: ``` <!-- Select all event in this year --> $thisYear = test::where('id', '=', $id) ->where('YEAR(start)', '=', date("Y")); <!-- Group all events by year --> $years = test::where('id', '=', $id) ->groupBy('YEAR(start)'); ``` In the first code I would like to get all the events that there is in this year (2013) In the second I would like to group all events in Years. Hopes somebody can help. Regards, Andreas