mos*_*toh 5 notifications real-time broadcast laravel laravel-5
我用的是laravel 5.3
我创建了一个在线商店网站。
如果用户登录并选择产品,然后单击“确定”按钮,图标购物车中将会有实时通知。
我的代码如下所示:
如果用户选择产品和确定按钮,它将运行此功能:
public function addNotificationCart()
{
Notification::send(auth()->user(), new CartNotification($cart));
}
Run Code Online (Sandbox Code Playgroud)
然后 :
public function toBroadcast($notifiable) {
return new BroadcastMessage([
'id' => $this->data->id,
'time' => $this->data->created_at,
'group' => 'cart'
]);
}
Run Code Online (Sandbox Code Playgroud)
我的 JavaScript 代码如下所示:
Echo.private('App.User.' + window.Laravel.authUser.id).notification((notification) => {
// run this statement if exist notification
})
Run Code Online (Sandbox Code Playgroud)
如果代码运行,它就有效
我想在我的网站上添加一个新功能。所以当用户未登录时,用户也可以添加购物车,并且会显示通知购物车
对我来说重要的是我如何去做?
在这个部分 :
Notification::send(auth()->user(), new CartNotification($cart));
Run Code Online (Sandbox Code Playgroud)
和 :
window.Laravel.authUser.id
Run Code Online (Sandbox Code Playgroud)
它需要记录用户数据和 ID
如果用户没有登录,如何填写?
| 归档时间: |
|
| 查看次数: |
1821 次 |
| 最近记录: |