Hi, I have this js code
var pusher = new Pusher('my pusher key', { cluster: 'ap2' }); var channel = pusher.subscribe('my-channel'); channel.bind('my-event', function(data) { console.log(data); });
This is my Laravel code
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'; }
This is the calling code
return event( new \App\Events\New_pos_online_order_event('aa'));
Now is the code
channel.bind('my-event', function(data) { console.log(data); });
always returns [] on the 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
public function broadcastOn() { return 'my-channel'; } public function broadcastAs() { return 'my-event'; }
The code does not work and returns nothing on the console So how can I pass parameters on Pusher and Laravel using js Thanks..
You need to define the functionbroadcastWith
You will receive the array in the data of the bound function