2017-02-25 187 views
1

我有一个问题,我现在正在尝试整天修复。我跟着 this教程。目标是与Laravel echo,vue.jspusher进行聊天。Laravel回声推送器未收到广播事件

我已经完成了一切与教程完全一样,但由于某种原因,我没有收到我的pusher控制台中的任何事件。只有连接出现:enter image description here

但没有事件发生。我火灾的事件是这样的:

<?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事件类:

public function broadcastOn() 
{ 

    dd('test'); 

    return new PrivateChannel('chat'); 
} 

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

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

回答

0

它看起来喜欢你是以下this教程。我也很难弄清楚。我已经回答了here。你能检查一下吗?

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

让我知道如果您有任何问题。谢谢:)

0

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

您一直在遵循的教程的完整演示代码是on github,因此您可能需要查看该代码并查看您的不同之处。

0

如果您使用的是Laravel 5.4,请确保您已设置通道验证。

例如,在你routes/channels.php文件,应该是这样的:

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