Laravel sort conversations by last message
问题 I have a Conversation model that has many ConversationMessage models. Now I want to sort the conversations based on the last message of the conversation. Basically like WhatsApp. How do I build the query? As a sidenote to my code: Conversation contains a user ( user_id ) and a company associated ( company_id ). Company has a belongsToMany relation to user. Conversation::whereHas('company', function ($q) use ($userId) { $q->whereHas('users', function ($q1) use ($userId) { $q1->where('users.id'