如何在php中访问facade上的属性



当我转储这个Customer::where('email', '=', $inputObj['email']-first();时,输出有一些属性。其中一些具有CCD_ 2,而其他具有+。例如,一个是+exists: true,我可以通过->exists()访问它,它会返回true。另一个是#attributes: array:10 [...],我可以看到它是一个在dump中有值的关联数组,但我不能像这个->attributes或这个['attributes']那样访问。不同的符号意味着什么?我如何访问attributes属性中的值?

我真的很想深入了解正在发生的事情,所以任何有启发性的评论都很感激(:

这些符号用于可见性,请参考:

https://stackoverflow.com/a/4361582/8637968

您无法访问";属性";因为它是一个私有属性,请记住Laravel中的var_dump((或dd(((代表dump和die(是用于调试目的的,这就是为什么你会看到私有属性,但私有属性只能从类中访问,在Laravel的情况下,你可以访问";属性";数组作为属性本身,例如:假设您的Customer模型有一个名为"的列;name";,该列将在";属性";数组,您可以这样访问它:

$customer = Customer::where('email', '=', 'some_email@mail.com')->first();
$customer->name; // assuming that the model exists, i.e: if ($customer != null) {}

最新更新