[英]Code Executing without any error, but message not appearing on pusher debug console nor showing message in jsfiddle
我的控制器:這是觸發事件的方法。
public function fireUserNotification()
{
$payload = [
'app' => 'AppName',
'action' => 'supportActionReply',
'payload' => [
'message' => 'this is a message',
'foo' => 'bar',
'user_uuid' => auth()->user()->user_uuid
]
];
event(new \App\Events\User\NotifyUser($payload));
return response()->json(['message' => 'fired'],200)
}
我的事件:(這是從上面的控制器觸發的事件)
class NotifyUser implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public array $payload;
public function __construct(array $payload)
{
$this->payload = $payload;
}
public function broadcastOn()
{
return new Channel('channel.user');
}
public function broadcastAs()
{
return 'user-notification';
}
public function broadcastWith()
{
return [
'app' => 'AppName',
'action' => 'supportActionReply',
'payload' => [
'message' => 'this is a message',
'foo' => 'bar'
]
];
}
}
我在 Pusher Debug 控制台上沒有看到任何內容。
因為,我還沒有前端(目前正在開發 API),我正在 jsfiddle 上對其進行測試:
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/7.0/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('443xxxxxxxxxxxxxxxxx', {
cluster: 'us2'
});
var channel = pusher.subscribe('channel.user');
channel.bind('user-notification', function(data) {
console.log(data);
alert(JSON.stringify(data));
});
</script>
</head>
<body>
<h1>Pusher Test</h1>
<p>
Try publishing an event to channel <code>my-channel</code>
with event name <code>my-event</code>.
</p>
</body>
但是,我沒有在推送器上收到任何數據,相反,如果我從推送器調試控制台觸發事件,它會在 jsfiddle 上發布。
請讓我知道我做錯了什么或我可能遺漏了什么。
嘗試調用它:
broadcast(new \App\Events\User\NotifyUser($payload));
您的 Pusher Debug 控制台中是否出現任何內容?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.