Convert to eloquent

0

I have this query that making it run in workbench returns me well

SELECT msg.id, msg.messages,msg.readed, COUNT(cmt.message_id) as total FROM messages as msg inner join comments as cmt where cmt.message_id = msg.id;

or this one that also returns the same:

SELECT msg.id, msg.messages,msg.readed, COUNT(cmt.message_id) as total FROM messages as msg, comments as cmt where cmt.message_id = msg.id;

and what it returns is the following it shows me the ID , MESSAGE AND READ / NOLEID , QUANTITY OF COMMENTS strong>, but at the moment of converting it into eloquent it throws me this error:

  

"SQLSTATE [42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN (), MAX (), COUNT (), ...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: SELECT msg.id, msg.messages, msg.readed, COUNT (cmt.message_id) as total FROM messages as msg, comments as cmt where cmt.message_id = msg.id) "

What I understand this error tells me that you can not group and display the information, in summary you can only show the COUNT .

How can I get it back in the same row THE MESSAGE and the QUANTITY OF COMMENTS that a certain message has?

    
asked by Angel Omar Rojas Pacheco 14.10.2017 в 21:17
source

0 answers