lundi 23 janvier 2017

Retrieving the last user message from chat - inbox

I'm building a chat section of my website and here is what I came up with for the query for retrieving last message for inbox and the conversation.

     $chat_inbox = Message::where('author_id', $this->user->id)
        ->orWhere('recipient_id', $this->user->id)
        ->groupBy('unique_chat_id')
        ->latest();

the problem is that I need to find the last message that the other user sent, not the one sending the message. I can then display this message as unread in the inbox, but I also need to retrieve the conversation that the current user started even if the other use still have not responded.

This current query will get me the last message no matter who sent it. Any help is appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire