3

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

1 Answer 1

8

You are looking for DB::raw(). I think the following should work.

$thisYear = test::where('id', '=', $id)
    ->where(DB::raw('YEAR(start)'), '=', date('Y'));
1
  • Thanks - I had looked at raw queries, but couldn't quite understand them:-) Yours worked like a charm:-) Commented Nov 21, 2013 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.