首页 > 解决方案 > 使用没有错误消息的私人频道时无法从推送者那里获得响应

问题描述

使用公共频道时,我确实收到了响应,但是当我将其更改为私人频道并检查 channels.php 文件返回 true 时,我没有收到任何响应,并且从推送者方面,很明显消息正在到达那里但是laravel echo 之后没有得到响应

标签: phplaravelvue.jspusherlaravel-echo

解决方案


希望我的代码能帮助您配置事件

public function broadcastOn()
    {
        return new PrivateChannel('Chat.'. $this->chat->user_id.'.'.$this->chat->friend_id);
    }

添加频道

 Broadcast::channel('Chat.{user_id}.{friend_id}', function ($user, 
  $user_id,$friend_id) {
    return $user->id == $friend_id;
 });

从此通道获取数据

axios.post('/chat/getchat/'+friendId).then((response)=>{
        this.chats = response.data;
      });
      Echo.private('Chat.'+friendId+'.'+userId)
      .listen('BroadcastChat',(e)=>{
        this.chats.push(e.chat);
      });

推荐阅读