为什么Laravel&Pusher在本地主机上不起作用,但在生产环境上起作用?

时间:2019-03-27 21:15:17

标签: php laravel vue.js

我正在制作一个小约会应用程序,在其中使用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));

enter image description here

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

相关问题