Laravel 5事件不发送事件

时间:2019-02-07 22:11:11

标签: php laravel-5 vue.js laravel-5.5

我尝试在laravel中获取事件。 1)通话事件:

  broadcast(new MessagePosted($message, $user))->toOthers();

2)消息已发布:

  public function __construct(Message3 $message, User $user)
    {
        $this->message=$message;
        $this->user=$user;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('chatroom');
    }

修复.env:

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=from https://dashboard.pusher.com/
PUSHER_APP_KEY= from https://dashboard.pusher.com/
PUSHER_APP_SECRET= from https://dashboard.pusher.com/
PUSHER_CLUSTER=en 

添加bootstrap.js:

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    encrypted: true
});

刀片服务器上的侦听器:

  mounted() {
                this.echo.join('chatroom')
                    .here()
                    .joining()
                    .leaving()
                    .listen('MessagePosted', (e) => {
                        console.log(e);
                        console.log("messages get!")
                    });
            },

由于某种原因,该事件不起作用。在文件MessagePosted中,所有工作(检入转储)。

0 个答案:

没有答案