我正在从事一个项目,因此我想实时向用户发送通知。所以我用过Laravel Echo和Pusher。现在我面临一个问题,通知已成功发送,广播和存储在数据库中,但Laravel Echo并未收到,因此未在浏览器中显示。有人可以帮我吗?
我已经检查了Pusher凭证以及.env文件。 Pusher调试控制台也可以正常工作。
Channel.php
Broadcast::channel('App.SellEmployee.{userid}', function ($SellEmployee, $id){
return $SellEmployee->userid == $id;
});
Notification.vue
mounted() {
Echo.private('App.SellEmployee.' + this.userid)
.notification((notification) =>
{
console.log('Random Message');
let newUnreadNotifications = {data:{message:notification.message}};
this.unreadNotifications.push(newUnreadNotifications);
});
}
SellEmployee-模型
public function receivesBroadcastNotificationsOn()
{
return 'App.SellEmployee.'.$this->id;
}
broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => "eu",
'useTLS' => true,
],
],