修复:FriendAdded/FriendRemoved 加 broadcastAs() 修复私有频道事件名不匹配
前端 .listen('.FriendAdded') 匹配的是短名 FriendAdded,
但默认广播名是 App\Events\FriendAdded(全类名),导致监听器永远不触发。
加 broadcastAs() 返回短名后两端匹配,弹窗可正常弹出。
This commit is contained in:
@@ -47,6 +47,17 @@ class FriendAdded implements ShouldBroadcast
|
||||
return new PrivateChannel('user.'.$this->toUsername);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定广播事件名称(短名),供前端 listen('.FriendAdded') 匹配。
|
||||
*
|
||||
* 默认广播名为全类名 App\Events\FriendAdded,
|
||||
* 指定短名后前端只需 .listen('.FriendAdded')。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'FriendAdded';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播负载:包含发起人信息和互相好友状态,供前端弹窗使用。
|
||||
*
|
||||
|
||||
@@ -47,6 +47,17 @@ class FriendRemoved implements ShouldBroadcast
|
||||
return new PrivateChannel('user.'.$this->toUsername);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定广播事件名称(短名),供前端 listen('.FriendRemoved') 匹配。
|
||||
*
|
||||
* 默认广播名为全类名 App\Events\FriendRemoved,
|
||||
* 指定短名后前端只需 .listen('.FriendRemoved')。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'FriendRemoved';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播负载:包含发起人信息和之前互相好友状态,供前端弹窗使用。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user