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');
}
控制器
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]);
}
我从活动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
我不知道为什么消息和s_number是正确的,但是诸如city和p_id之类的其他消息为null,未定义?
,对象键是message,s_number,socket
为什么向关键字显示“ socket”?
如何解决该问题以获得这两个变量$ city和$ p_id?
感谢任何帮助。
答案 0 :(得分:0)
我找到了愚蠢的答案 每当更改代码 您必须重新启动 1. laravel-echo-server启动 2.php工匠队列:工作
一切都很好〜