2017-01-28 38 views
1

我在使用Laravel Echo推送器時使用存在信道時遇到問題。當我發起一個事件時,我從BroadcastException得到500錯誤,而沒有響應正文,這對我來說很難調試它。當我查看推送器調試控制檯時,推送者聽到存在事件。所以我認爲我的事件從未被解僱過Pusher。這裏是我的網絡選項卡中的預覽Laravel Echo 500錯誤未收到推送器事件

enter image description here

我的控制器:

public function store() { 
    $user = auth()->user(); 

    $message = $user->messages()->create([ 
     'message' => request('message') 
    ]); 

    event(new MessageReceived($message, $user)); 

    return ['status' => 'OK']; 
} 

namespace App\Events; 


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

    public $message; 

    public $user; 

/** 
* Create a new event instance. 
* 
* @return void 
*/ 
public function __construct(Message $message, User $user) 
{ 
    $this->message = $message; 

    $this->user = $user; 
} 

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

,這裏的MessageReceived類是我vuejs

mounted() { 
    axios.get('/messages') 
     .then(response => { 
      this.messages = response.data 
     }) 
     .catch(error => { 
      console.log(error) 
     }) 

    Echo.join('chatroom') 
     .listen('MessageReceived', (e) => { 
      console.log(e) //never get into this 
     }) 
}, 

我找不到錯誤在哪裏。我使用cluster ap1,並在broadcasting.php和我的bootstrap.js中聲明。任何人都可以幫助我?

回答

1

這可能是由您的配置中的錯誤引起的。這裏有一些事情要檢查:

  1. 在你.env文件,確保推進器ID,鑰匙和密鑰都設置正確。
  2. 如果從Laravel 5.3升級到5.4 Laravel,請注意.env變量PUSHER_KEY現在PUSHER_APP_KEYPUSHER_SECRET現在PUSHER_APP_SECRET
  3. 是在你config/broadcasting.php,確保羣集設置正確。
  4. 如果你不是在HTTPS,您可能需要在「encrypted鍵設置爲false

    'options' => [ 
        'cluster' => 'ap1', // change this to your app's cluster 
        'encrypted' => false, 
    ], 
    
+1

是在我的情況,導致問題的4號,因爲我在本地主機上XAMPP運行 – ishadif

+0

@ishadif太好了!如果您發現我的回答有幫助或正確,希望您可以將其標記爲接受的答案。謝謝! – jcsoriano

+1

其實我很久以前就解決了這個問題。但我認爲你的回答會幫助其他人得到類似的問題。 – ishadif