问题
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