Reputation: 659
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
Upvotes: 3
Views: 2814
Reputation: 9280
You are looking for DB::raw(). I think the following should work.
$thisYear = test::where('id', '=', $id)
->where(DB::raw('YEAR(start)'), '=', date('Y'));
Upvotes: 8