dongqiang4986 2019-08-12 12:37
浏览 325

Laravel广播适用于一个用户

I am doing a notification tracking by following a simple example from the internet. Unfortunately, so far, I've managed to make it work for only one user. When I open two users, the message from A to B works, but from B to A does not work. Can someone help me?

channels.php

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

bootstrap.js

window.Pusher = require('pusher-js');
import Echo from "laravel-echo";

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'some-key',
    cluster: 'mt1',
    forceTLS: true
});

global.js

    var urlChannel = 'App.User.' + $('#user_logado_id').val();
    window.Echo.private(urlChannel)
        .notification((notification) => {
            addNotificacao(notification);
        });

Send notification to user.

$user->notify(new NotificacaoPadrao($param));

I would like notifications to be sent to all users.

  • 写回答

2条回答 默认 最新

  • dousao2186 2019-08-12 12:43
    关注

    That's because first user's channel is App.User.1, and second one is App.User.2. You should create a channel that's shared for both of them. For example: App.Channel.1-2.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料