如何在 php 中访问外观上的属性

How to access properties on a facade in php

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

中的值

我真的很想深入了解正在发生的事情,因此欢迎任何有启发性的评论(:

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

您无法访问“属性”,因为它是私有的 属性,请记住 Laravel 中的 var_dump() 或 dd()(代表转储和死亡)是旨在用于调试目的,这就是为什么您会看到私有属性,但是私有属性只能从 class 中访问,在 Laravel 的情况下,您可以访问“ attributes”数组作为属性本身,例如:假设对于您的 Customer 模型,您有一个名为“name”的列,该列将位于“attributes”数组中,您可以像这样访问它:

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