How to use Laravel Eloquent with groupBy?
This is my code but I got errors all the time:
Message::whereColumn('host_id', 'sender_id')
->groupBy('host_id')
->orderBy('created_at', 'DESC')
->paginate(10);
The error message is:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'project_db.messages.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select * from
messages
wherehost_id
=sender_id
group byhost_id
order bycreated_at
desc limit 10 offset 0)
What I'm trying to achieve is display messages as branches (groups), threads.