Chat with notice notification in laravel

1

I'm developing a chat with Laravel , and I followed this tutorial . The chat is working fine, but I wanted to know how to make a notification like this:

When a message is sent to a user and the user has not yet read it.

Can anyone help me?

    
asked by anonymous 05.09.2018 / 18:41

1 answer

1

In your migration "messages", add:

 $table->timestamp('read_at')->nullable();

With this field, you can know the messages that have already been read and those that have not been read.

Now, you simply search for unread messages like this:

$mensagemsNaoLidas = App\Message::where('user_id', $user_id)->whereNull('read_at')->get();

And return your view values as follows:

return view('suaview', $mensagensNaoLidas);

With this, you pass to your view these unread messages and formats it according to the photo in this way:

a.notif {
  position: relative;
  display: block;
  height: 50px;
  width: 50px;
  background: url(...url para o icone...);
  background-size: contain;
  text-decoration: none;
}
.num {
  position: absolute;
  right: 11px;
  top: 6px;
  color: #fff;
}

<a href="" class="notif">
<span class="num">
<?php
     echo count($mensagensNaoLidas);
?>
</span></a>

In this way, it will display according to the image, and then you decide how you want the code to decide when it has read a message.

    
05.09.2018 / 18:57