S
S
Sergey2019-06-20 14:32:26
Laravel
Sergey, 2019-06-20 14:32:26

How to get unread notifications?

Good afternoon.
I use a bunch of Redis + socket.io + laravel-echo server
If the user is online - everything is ok. notifications are coming. But the task is worth it - to display unread notifications if the user was offline. Messages are placed as read when closing via
ajax Redis - only publishes a message to the channel and it doesn't care if someone is there or not.
To do this, I made a Notification model

public static function publish($userId, $data) {
    self::create([
      'userId' => $userId,
      'data' => $data
    ]);

      Redis::publish('private-user.'.$userId, json_encode($data));
    }

and, accordingly, in the code where I need to notify, I call
Notification::publish($user->id, $data);
Everything is fine. but I can't find how to catch on the backend - joining a user to a channel - to get all unread messages and send it to him? does laravel-echo-server have events?
or just in the base controller - add reading unread messages and notifications?
Or am I not digging there at all?
Thanks

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question