Answer the question
In order to leave comments, you need to log in
Select last unique record via Eloquent Laravel?
$messages = $user->messagesReceived()->groupby('to_user_id')->distinct()->orderBy('created_at', 'DESC')->get();
// и
$messages = $user->messagesReceived()->groupby('to_user_id')->orderBy('created_at', 'DESC')->get();
Illuminate \ Database \ QueryException (42803)
SQLSTATE[42803]: Grouping error: 7 ERROR: column "messages.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: select distinct * from "messages" where "messages"."to_user_... ^ (SQL: select distinct * from "messages" where "messages"."to_user_id" = 1 and "messages"."to_user_id" is not null group by "to_user_id" order by ....
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question