0

我正在尝试像laravel 文档一样设置广播。我正在使用推杆。

这是我的 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"));

这是我的频道.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.

有人可以帮忙吗?

4

0 回答 0