我在推送器的帮助下播放我的活动,它工作得很好,但是当我使用队列实现时,推送器没有接收任何广播或者可能是事件不是广播。我不是了解问题所在。代码如下,请帮助我
控制器功能
public function index()
{ $this->user_id=2;
Event::fire(new UpdateDeviceStatus($this->user_id));
}
活动档案
class UpdateDeviceStatus extends Event implements ShouldBroadcast
{
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $devices;
public function __construct($id)
{
$this->devices=Device::with('units')->where('user_id',$id)->get();
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['update-status'];
}
}
js file
Pusher.logToConsole = true;
var pusher = new Pusher('key', {
encrypted: true
});
var channel = pusher.subscribe('update-status');
channel.bind('App\\Events\\UpdateDeviceStatus', function (data) {
console.log(data);
});
答案 0 :(得分:1)
我遇到了同样的问题,并意识到我只是忘了听队列:php artisan queue:listen redis