您需要在channels.php
路由文件中对每个团队频道的用户进行身份验证:
// loop teams to create channel names like teams.team1.1, teams.team2.1
// {id} is the user's primary key
Broadcast::channel("teams.{$team->name}.{id}", function (Authenticatable $user, $id) {
return (int)$user->getAuthIdentifier() === (int)$id;
});
// have Echo listen for broadcast events on the same channels.
Echo.private('teams.team1.1')
.listen('SomeTeamEvent', callback)
.listen('AnotherTeamEvent', callback2)
...
.listen('LastTeamEvent', callbackX)
...
Echo.private('teams.team2.1')
.listen('SomeTeamEvent', anotherCallback)
.listen('AnotherTeamEvent', anotherCallback2)
...
.listen('LastTeamEvent', anotherCallback2)