mardi 24 novembre 2015

Chat App - List 10 latest messages from each chat on page load

I have a chat app with multiple chats in one page. Each chat I want to get the latest 10 messages to load first (and then lazy load the older ones if they want them) when the page loads.

I want to use the whereIn that laravel offers so I can get multiple chat groups in a single query.

My current code is:

$chats = ChatMessage::whereIn('group_id', $group_ids)->orderBy('message_date', 'ASC')->take(10)->get();

But I realize that the take(10) only takes 10. I want to take 10 for every group_id in the table.

What is the most efficient way to do this in laravel 5.1?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire