php - 使用 Laravel 5.4 和推送器向公共(public) channel 广播通知

标签 php laravel broadcast pusher

我的通知 RealtimeNotification.php 有:

public function via($notifiable)
{
    return ['broadcast'];
}

public function toBroadcast($notifiable){
    return new BroadcastMessage([
        'name' => 'John Snow'
    ]);
}

在我看来,我有一个与我的推送帐户连接的推送对象:

var channel = pusher.subscribe('private-App.User.1');
channel.bind('App\\Notifications\\RealtimeNotification', function(data) {
    console.log(data);
});

所以,如果我像这样使用,Pusher 在控制台中给我这个错误,也许因为它是一个私有(private) channel ,我没有为 Pusher 配置任何身份验证

Failed to load resource: the server responded with a status of 404 (Not Found)
Pusher : Couldn't get auth info from your webapp : 404

我的问题是,如何广播到公共(public) channel ?

在 Laravel 5.4 文档中,说道: “通知将在使用 {notABLE}.{id} 约定格式化的私有(private) channel 上广播。”

我认为应该有一个方法,但我仍然找不到它,欢迎任何帮助。

最佳答案

channel 应该是 Channel、PrivateChannel 或 PresenceChannel 的实例。 Channel 的实例代表任何用户都可以订阅的公共(public) channel ,而 PrivateChannels 和 PresenceChannels 代表需要 channel 授权的私有(private) channel ......如 laravel 官方文档中所述

关于php - 使用 Laravel 5.4 和推送器向公共(public) channel 广播通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42293081/

相关文章:

go - 有没有办法广播到redis中的每个 channel ?

php - Paypal 从一个账户转账到另一个账户

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

php - Laravel 中的位置 header

php - 在 Laravel 5 中间件中操作 JSON

c - MPI 超立方体广播错误

php - 浏览器将 PHP -> 符号后的所有内容解释为文本

php - YouTube配额用完了,我有什么选择?

laravel - 无法以编程方式在 GitHub 中创建标签 - ISO8601 时间戳无效

apache-spark - MapWithState 给出 java.lang.ClassCastException : org. apache.spark.util.SerializableConfiguration cannot be cast while recovering from checkpoint