【问题标题】:Why is Laravel & Pusher not working on localhost but works on production?为什么 Laravel 和 Pusher 不在 localhost 上工作,但在生产上工作?
【发布时间】:2019-03-27 21:15:16
【问题描述】:

我正在制作一个使用 Pusher 和 Laravel 的小型约会应用程序。我使用一个名为NewMessage 的事件并在频道msg.{userId} 上收听。聆听有效,但广播事件无效。但它适用于生产。

我的代码如下:

NewMessage.php

    public function __construct(Message $message, $toUserId, $conversation)
    {
        //
        $this->message = $message;
        $this->toUserId = $toUserId;
        $this->conversation = $conversation;
    }
    /**
     * Get the channels the event should broadcast on.
     *
     * @return Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('msg.'.$this->toUserId);
    }
    public function broadcastAs()
    {
        return 'NewMessage';
    }

ConversationController.php

event(new NewMessage($message, $toUserId, $conversation));

【问题讨论】:

  • 您在生产中是否有 SSL 连接? :)
  • 是的,它在 heroku 上

标签: php laravel vue.js


【解决方案1】:

检查生产应用程序的 .env 文件并将 BROADCAST_DRIVER=log 设置为 BROADCAST_DRIVER=pusher

【讨论】:

    【解决方案2】:

    在 config/broadcasting.php 中,我只是将 encrypted 设置为 false 就可以了!

    【讨论】:

      猜你喜欢
      • 2014-10-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 2017-03-10
      • 2021-01-01
      • 2021-12-28
      相关资源
      最近更新 更多