Here is my js
var room_id = 3;
Echo.join('room'+room_id)
.listen('PersonalChat', (response)=>{
// console.log(response);
});
Here is PersonalChat.php
public $data;
public function __construct($data)
{
$this->data=$data;
}
public function broadcastOn()
{
return new PresenceChannel('room'."How to get room_id");
}
Here is My channels.php
Broadcast::channel('rooom'.'How to get roomid', function ($user) {
return EventHelper::Filter_UsingEvent($user);
});
I asked my question in my channels.php and PersonalChat.php
Again May I say
My question is ** How to get room id ** in channels.php and PersonalChat.php
Thank you all
Sorry for my english skill
you can accept param in channel.php
like {roomId}
then in call back you will get that value
Broadcast::channel('rooom.{roomId}'., function ($user,$roomId) { // $roomId will get
return EventHelper::Filter_UsingEvent($user);
});
then in js
var room_id = 3;
Echo.join('room.'+room_id)
.listen('PersonalChat', (response)=>{
// console.log(response);
});
and in PersonalChat.php
public $data;
public function __construct($data)
{
$this->data=$data;
}
public function broadcastOn()
{
return new PresenceChannel('room'.$this->data->roomId); // you need to pass room id when event is trigger
}
ref link https://laravel.com/docs/8.x/broadcasting#example-application-authorizing-channels