我正在尝试设置广播,就像laravel documentation一样。我正在使用推杆。
这是我的FriendRequestSent事件:
class FriendRequestSent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $id;
public function __construct($id)
{
$this->id = $id;
}
public function broadcastOn()
{
return new Channel('friend-request.' . $this->id);
}
}
我称之为:
event(new FriendRequestSent("5a22f7e72e069a2e64001ed5"));
这是我的channel.php
Broadcast::channel('friend-request.{receiverId}', function ($user, $receiverId) {
return true;
});
这是我在页面上的脚本:
<script>
Echo.private(`friend-request.${receiverId}`)
.listen('FriendRequestSent', (e) => {
console.log(e);
});
</script>
就像文档一样。但我在浏览器的控制台中收到此错误:
Uncaught ReferenceError: receiverId is not defined.
有人可以帮忙吗?