0
我在推送器的幫助下廣播我的事件,但它運行良好,但是當我使用隊列實現時,推送器沒有收到任何廣播或可能事件不是廣播。 「M不明白的問題is.Code在下面給出,請幫我當在我們的項目中使用隊列時,事件廣播不工作
控制器功能
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文件
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);
});