How can I make realtime notification for user who are not login?

断了今生、忘了曾经 提交于 2019-12-28 04:32:07

问题


I use laravel 5.3

I created an online store website.

If user logs in and chooses a product then okay button, there will be realtime notification in icon cart.

My code looks like this :

If user selects product and okay button, it will run this function :

public function addNotificationCart()
{
    Notification::send(auth()->user(), new CartNotification($cart));
}

Then :

public function toBroadcast($notifiable) {
    return new BroadcastMessage([ 
        'id'        => $this->data->id,
        'time'      => $this->data->created_at,
        'group'     => 'cart'
    ]);
}

And my javascript code looks like this :

Echo.private('App.User.' + window.Laravel.authUser.id).notification((notification) => {
     // run this statement if exist notification        
})

If the code run, it works

I want to add a new feature on my website. So when the user is not logged in, the user can also add cart and there is will display notification cart

What matters to me is how I do it?

In this section :

Notification::send(auth()->user(), new CartNotification($cart));

And :

window.Laravel.authUser.id

It requires user data being logged and id

How do I fill it if the user is not logged on?

来源:https://stackoverflow.com/questions/45877837/how-can-i-make-realtime-notification-for-user-who-are-not-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!