1

我正在使用一个广播用户对象的事件。用户对象包含

  "id":2,
  "name":"Clark",
  "surname":"Beer",
  "email":"schultz.arthur@example.com",
  "role":"user",
  "information":{  
     "user_id":2,
     "bio":"Dicta fugit voluptas fugiat doloremque.",
     "profile_picture_id":2,
     "image":{  
        "id":2,
        "path":"https:\/\/lorempixel.com\/640\/640\/people\/?54438"
     }
  }

但问题是,广播只发送没有“信息”子对象的用户模型,这是由 SerializesModels 引起的。

当我删除 SerializesModels 导入时,广播工作正常,但仍然使用 SerializesModels 特征也会很好。

有没有办法在使用 SerializesModels 特征时包含子对象?

class searchUserEvent implements ShouldBroadcastNow {
   use Dispatchable, InteractsWithSockets, SerializesModels;

   /**
    * Create a new event instance.
    *
    * @return void
    */

    public $users;

    public function __construct($users)
    {
        $this->users = $users;
    }

    /**
    * Get the channels the event should broadcast on.
    *
    * @return \Illuminate\Broadcasting\Channel|array
    */
    public function broadcastOn()
    {
        return new Channel('searchUser');
    }
4

0 回答 0