Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $messages = ChatMessages::select(DB::raw('t.*'))
- ->from(DB::raw('(SELECT * FROM chat_messages ORDER BY created_at DESC) t'))
- ->whereIn('message_id', $messageIds)
- ->groupBy('message_id')
- ->orderBy('created_at', 'DESC')
- ->paginate(3);
- +----+----------+---------------------+-----------+
- | id | message_id | created_at | name |
- +----+----------+---------------------+-----------+
- | 1 | 1000 | 2017-01-01 06:03:40 | Anna |
- +----+----------+---------------------+-----------+
- | 2 | 1007 | 2017-01-02 07:13:20 | Becky |
- +----+----------+---------------------+-----------+
- | 3 | 1000 | 2017-01-03 08:20:12 | Christina |
- +----+----------+---------------------+-----------+
- | 4 | 1004 | 2017-01-03 08:20:15 | Dorothy |
- +----+----------+---------------------+-----------+
- | 5 | 1004 | 2017-01-04 09:25:45 | Emma |
- +----+----------+---------------------+-----------+
- | 6 | 1000 | 2017-01-05 10:30:10 | Fiona |
- +----+----------+---------------------+-----------+
- | 7 | 1007 | 2017-01-05 10:33:23 | Gigi |
- +----+----------+---------------------+-----------+
- | 8 | 1007 | 2017-01-06 12:46:34 | Heidi |
- +----+----------+---------------------+-----------+
- | 9 | 1000 | 2017-01-06 12:46:34 | Irene |
- +----+----------+---------------------+-----------+
- | 10 | 1007 | 2017-01-07 14:58:37 | Jane |
- +----+----------+---------------------+-----------+
- | 11 | 1007 | 2017-01-07 14:58:37 | Katy |
- +----+----------+---------------------+-----------+
- +----+----------+---------------------+-----------+
- | id | message_id | created_at | name |
- +----+----------+---------------------+-----------+
- | 11 | 1007 | 2017-01-07 14:58:37 | Katy |
- +----+----------+---------------------+-----------+
- | 9 | 1000 | 2017-01-06 12:46:34 | Irene |
- +----+----------+---------------------+-----------+
- | 5 | 1004 | 2017-01-04 09:25:45 | Emma |
- +----+----------+---------------------+-----------+
- +----+----------+---------------------+-----------+
- | id | message_id | created_at | name |
- +----+----------+---------------------+-----------+
- | 4 | 1004 | 2017-01-03 08:20:15 | Dorothy |
- +----+----------+---------------------+-----------+
- | 2 | 1007 | 2017-01-02 07:13:20 | Becky |
- +----+----------+---------------------+-----------+
- | 1 | 1000 | 2017-01-01 06:03:40 | Anna |
- +----+----------+---------------------+-----------+
- AppConversationMessages::whereIn('message_id', $messageIds)
- ->orderBy('created_at', 'DESC')
- ->paginate(3)
- ->unique('message_id');
- +----+----------+---------------------+-----------+
- | id | message_id | created_at | name |
- +----+----------+---------------------+-----------+
- | 11 | 1007 | 2017-01-07 14:58:37 | Katy |
- +----+----------+---------------------+-----------+
- | 9 | 1000 | 2017-01-06 12:46:34 | Irene |
- +----+----------+---------------------+-----------+
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement