如何访问对象属性?

奶油
MyObject {#300 ▼
  +dataType: DataType {#323 ▶}
  +data: Course {#328 ▼
    #connection: "mysql"
    #table: null
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:32 [▶]
    #original: array:32 [▶]
    #changes: array:2 [▼
      "prop" => 1
      "updated_at" => "2018-08-08 11:50:39"
    ]
    #casts: []
    #dates: []
    #dateFormat: null
    #appends: []
    #dispatchesEvents: []
    #observables: []
    #relations: []
    #touches: []
    +timestamps: true
    #hidden: []
    #visible: []
    #fillable: []
    #guarded: array:1 [▶]
  }
}

我使用以下命令在屏幕上打印该对象

dd($args->data);

现在,我需要检查内部是否有更改,然后尝试通过以下方式访问该属性:

dd($args->data->changes);

要么

dd($args->data['changes']);

但是我可以得到一个空值,而不是上面看到的数组。如何访问“更改”?

Hieu Le

您的数据似乎是一个雄辩的模型。changes属性是模型类受保护成员。因此,您不能从外部访问它。

dd函数的输出中,公共成员以+字符为前缀,受保护成员以#字符为前缀您可以查看这些前缀,以了解要访问的属性的可见性。

要获得Eloquent模型的更改,请使用getChanges()方法。对于您的情况,您应编写如下代码:

dd($args->data->getChanges());

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章