我在 Laravel Echo 中使用带有推送器的存在通道时遇到了问题。当我触发一个事件时,如果没有响应主体,我会收到 500 错误,BroadcastException
这对我来说很难调试。当我查看推送器调试控制台时,推送器监听了存在事件。所以我认为我的事件从未被推送给 Pusher。这是我的网络标签中的预览
我的控制器:
public function store() {
$user = auth()->user();
$message = $user->messages()->create([
'message' => request('message')
]);
event(new MessageReceived($message, $user));
return ['status' => 'OK'];
}
MessageReceived
班级_
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');
}
}
这是我的 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
})
},
我找不到错误在哪里。我使用集群 ap1 并broadcasting.php
在我的bootstrap.js
. 任何人都可以帮助我吗?