queue.blade.php
Echo.channel('everyone')
.listen('Queue_number', function (e) {
console.log('e='+e);
console.log('e keys='+Object.keys(e));
console.log('socket='+e.socket);
console.log('city='+e.city);
console.log('p_id='+e.p_id);
console.log('message='+e.message);
console.log('s_number='+e.s_number);
app/Events/Queue_number.php
class Queue_number implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $message;
public $s_number;
public $city;
public $p_id;
public function __construct($message,$s_number,$city,$p_id)
{
$this->message = $message;
//$this->s_number = $s_number;
$this->s_number = '1234';
$this->city = '236';
$this->p_id = $p_id;
}
public function broadcastOn()
{
return new Channel('everyone');
}
controller
public function queue_add(Request $request)
{
$message = $request->validate(['message'=>'required']);
$s_number=$request->name;
$city=$request->city;
$p_id=$request->p_id;
broadcast(new Queue_number($message['message'],$s_number,$city,$p_id));
//->toOthers()
return response()->json(['status'=>'success','message'=>$message['message'],'s_number'=>$s_number,'city'=>$city,'p_id'=>$p_id]);
}
I received the console from the Events Queue_number.php
e=[object Object]
63:615 e keys=message,s_number,socket
63:616 socket=null
63:617 city=undefined
63:618 p_id=undefined
63:619 message=1
63:620 s_number=1234
I don't know why the message and s_number is right but the others like city and p_id is null, undefined?
and the object key is message,s_number,socket
why shows 'socket' the key word?
how to fix the problem to get these two variables $city and $p_id?
thanks any helps.
I find the stupid answer whenever change the code You must restart the 1.laravel-echo-server start 2.php artisan queue:work
and everything is fine~