[英]pusher pass parameter in laravel broadcastAs
hi i have this js code嗨,我有这个 js 代码
var pusher = new Pusher('my pusher key', {
cluster: 'ap2'
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data)
{
console.log(data);
});
and this is my laravel code这是我的 laravel 代码
protected $pos_invoice;
public function __construct($pos_invoice)
{
$this->pos_invoice = $pos_invoice;
}
public function broadcastOn()
{
return new Channel('my-channel');
}
public function broadcastAs()
{
return 'my-event';
}
and this is the call code这是调用代码
return event( new \App\Events\New_pos_online_order_event('aa'));
now the code现在的代码
channel.bind('my-event', function(data)
{
console.log(data);
});
always return [] on console so i tried this总是在控制台上返回 [] 所以我尝试了这个
public function broadcastAs()
{
return 'my-event.'.$this->pos_invoice;
}
and this和这个
public function broadcastOn()
{
return new Channel('my-channel'.'asdfasdf');
}
when i change anything on当我改变任何东西时
public function broadcastOn()
{
return 'my-channel';
}
public function broadcastAs()
{
return 'my-event';
}
the code not working and not returning anything on console so how can i pass parameter on pusher and laravel with js thanks ..代码不工作,也没有在控制台上返回任何东西,所以我怎么能用 js 在 pusher 和 laravel 上传递参数谢谢..
You need to define the function broadcastWith你需要定义函数broadcastWith
**
* Get the data to broadcast.
*
* @return array
*/
public function broadcastWith()
{
return ['pos_invoice' => $this->pos_invoice];
}
You will receive the array in the data of the bind function您将在绑定函数的数据中收到数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.