I use laravel 5.3
I created an online store website
If user login, and user choose product then okay, there will be realtime notification in icon cart
My code like this :
If user select product and okay, 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 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?