Laravel echo pusher 没有收到广播事件

Laravel echo pusher not receiving broadcast events

我有一整天都在努力解决的问题。我关注了 this教程。目标是与 Laravel echovue.jspusher 聊天。

我完全按照教程完成了所有操作,但出于某种原因,我在 pusher console. Only the connection shows up:

中没有收到任何事件

但是没有事件。我触发的事件如下所示:

<?php

namespace App\Events;

use App\Message;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class MessageSent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * @var
     */
    public $user;

    /**
     * @var
     */
    public $message;

    /**
     * MessageSent constructor.
     * @param User $user
     * @param Message $message
     */
    public function __construct(User $user, Message $message)
    {
        $this->user = $user;
        $this->message = $message;
    }

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

我这样触发事件:

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

当我 dd('test'); 在我的 MessageSent 事件中点赞时 class:

public function broadcastOn()
{

    dd('test');

    return new PrivateChannel('chat');
}

dd('test'); 出现在我的网络选项卡中。

我正在使用 Laravel 5.4Vue.js 2.0 以及 Homestead。这里会发生什么?

从您的调试控制台屏幕截图来看,您从未订阅过任何频道,您是否为私人频道订阅设置了必要的身份验证?

您一直遵循的教程的完整演示代码是 on github,所以您可能想看看它,看看您的代码有何不同。

如果您使用 Laravel 5.4,请确保您已设置频道身份验证。

例如,在您的 routes/channels.php 文件中,应该有这样的内容:

Broadcast::channel('chat', function ($user) {
    return true; // change this to your authentication logic
});

您似乎在关注 this tutorial. I also had a hard time to figure it out. I already answered 。你能看看吗?

我致力于聊天系统中的打字功能。请查看 GitHub 上的代码。

如果您有任何问题,请告诉我。谢谢:)