Even with the reverse()->values being called on the messages of each conversation I'm still getting the newest messages above the older ones. I can easily fix this in my react front end , but I'm wondering what it is that I'm missing here.
Not sure about the reverse, but you cannot limit the number of messages by conversation like this. You will get a total of 20 messages across all conversations.
@Snapey What I did instead was $query->orderBy('created_at', 'asc')->take(-20); I changed the order to ascending and took the last 20, but I will investigate your earlier comment about limiting the messages to 20 tomorrow, I will make a factory for some conversations and messages to see the behavior and if it indeed limits it to 20 for all conversations combined I will fix it. Thanks!
I've decided that this would be the last version of the method, and I would just reverse the content in the front-end react component, however I'm not experiencing the issue @snapey described, I'm getting 20 messages per conversation and not 20 in total, so everything seems to be working fine.