Open packytagliaferro opened 7 years ago
Although it's too late to post something on this issue, however maybe for the new users it can help. This is a small hack to get the number of "Unread Messages" of each conversation for each user. add the following function to "Message.php" model:
public function getNumberOfUnreadMessagesAttribute()
{
return DB::table('messages')->select('id')->where('user_id','!=',Auth::user()->id)->where('conversation_id',$this->conversation->id)->where('is_seen',0)->count();
}
Then u can access it this way
Message->NumberOfUnreadMessages
I hope it helps.
Thank you very much @mohfrea! You're a true lifesaver!!
Is there a better way of getting the inbox count?
Right now I have this in my User model and load it in the head to a JS object so I can use it in a view component.
User Model:
head.php:
Then Finally in my Navigation I use it in a vue component:
<badge :inboxcount='window.Logic.inbox'></badge>
Doing it this way the
$inboxes = Talk::getInbox();
does a query for every message. So right now its 5 queries for just 2 messages. If a user has a big inbox it could get bigger I imagine.