I have two models Chat
and ChatMessage
.
Chat
has many ChatMessage
, i want to get all the Chat
ordered by the ChatMessage
created_at
So if the created_at
of the ChatMessage
has a date closest to today, that chat should be ordered first.
how could this be done?
I just have this
Chat::leftJoin('chat_messages', 'chats.id', '=', 'chat_messages.chat_id')
->orderBy('chat_messages.id', 'DESC');
but this does not work. i am not getting the newest row of chat_messages.
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2IORh2J
via IFTTT
Aucun commentaire:
Enregistrer un commentaire