I have the following SQL query:
return User::where("users.id", $id)
->select(array('rating.rate', User::raw('count(offers.id) AS ofrs, count(announcements.id) as appts')))
->join('announcements', 'users.id', '=', 'announcements.user_id')
->join('offers', 'users.id', '=', 'offers.user_id')
->join('rating', 'users.id', '=', 'rating.user_id')
->group_by('ofrs')
->get();
It gives me an error:
BadMethodCallException in Builder.php line 2508: Call to undefined method Illuminate\Database\Query\Builder::group_by()
Why does not work group by?
Also as way I tried:
return User::where("users.id", $id)
->selectRaw('rating.rate, count(offers.id) AS ofrs, count(announcements.id) as appts')
->groupBy('appts')
->groupBy('ofrs')
->join('announcements', 'users.id', '=', 'announcements.user_id')
->join('offers', 'users.id', '=', 'offers.user_id')
->join('rating', 'users.id', '=', 'rating.user_id')
->get();
Result:
SQLSTATE[42000]: Syntax error or access violation: 1056 Can't group on 'appts'
via Darama