Laravel 使用推送器广播状态频道无法传递参数

Laravel broadcasting a Presence Channel using pusher unable to pass parameters

我已逐步按照 https://laravel.com/docs/6.x/broadcasting 中的文档进行操作,并确保复制和粘贴以确保我没有犯任何错误。我可以很好地广播,一切都很好。因为我无法传递属性,所以不同 roomId 中的人被算作好像他们都在同一个房间里。 这是现场示例: https://prayershub.com/worship/82 - 82 是 worship_id 我想传递给:

Broadcast::channel('worship_presence_channel.{id}', function ($id) {
if(Auth()->check())
{
    $profile = Auth()->user()->Profile;

    $user = Auth()->user();

    $data = [
        'id' => $user->id,
        'name' => $user->name,
        'username' => $user->username,
        'avatar' => config('app.storage').$profile->profile_image,
        'url' => $profile->profile_url,
        'favorite_bible_verse' => $profile->favorite_bible_verse
    ];

    return $id;
}

});

发件人:

Echo.join(`worship_presence_channel.${id}`)
    .here((users) => {            
        worshipers=users;
        joinUser(worshipers);
        $('.group-count').html(worshipers.length);
        console.log(users);
    })
    .joining((user) => {
        worshipers.push(user);
        popupNewUser(user);
        joinUser(worshipers);
        $('.group-count').html(worshipers.length);
    })
    .leaving((user) => {
        worshipers = worshipers.filter(function(obj) {
            return (obj.id !== user.id);
        });
        popupLeaveUser(user);
        joinUser(worshipers);
        $('.group-count').html(worshipers.length);
    });

我也有一个看似无关紧要的事件,但它是这样的:

public function broadcastOn()
{
    return new PresenceChannel('worship_presence_channel.58');
}

public function broadcastAs()
{
    return 'worship_presence_channel.58';
}

任何人都可以告诉我我做错了什么,或者如果我把整件事都弄错了。请帮忙!

我弄明白了,我把上面的回显代码改成了这样:

Broadcast::channel('worship_presence_channel.{id}', function ($user, $id) {
if(Auth()->check())
{
    $profile = $user->Profile;

    $data = [
        'id' => $user->id,
        'name' => $user->name,
        'username' => $user->username,
        'avatar' => config('app.storage').$profile->profile_image,
        'url' => $profile->profile_url,
        'favorite_bible_verse' => $profile->favorite_bible_verse,
        'worships_id' => $id
    ];

    return $data;
}

});

我正在传递 2 个参数 $user、$id,它的工作原理与文档所说的一样!!!