[英]How to access properties on a facade in php
當我轉儲這個Customer::where('email', '=', $inputObj['email']-first();
輸出有一些屬性。其中一些有#
和其他有+
。例如,一個是+exists: true
,我可以通過->exists()
訪問它並返回true
。另一個是#attributes: array:10 [...]
我可以看到它是一個關聯數組,在dump
有值,但我不能像這樣訪問->attributes
或像這樣['attributes']
。不同的符號是什么意思,我如何訪問屬性屬性中的值?
我真的很想深入了解正在發生的事情,因此感謝任何有啟發性的評論(:
這些符號用於可見性,請參考:
https://stackoverflow.com/a/4361582/8637968
您無法訪問“屬性”,因為它是私有屬性,請記住 Laravel 中的 var_dump() 或 dd()(代表 dump 和 die)旨在用於調試目的,這就是您看到私有屬性的原因,但是私有屬性只能從類內部訪問,在 Laravel 的情況下,您可以訪問“屬性”數組中的屬性作為屬性本身,例如:假設對於您的客戶模型,您有一個名為“名稱”的列,該列將位於“屬性”數組內,您可以像這樣訪問它:
$customer = Customer::where('email', '=', 'some_email@mail.com')->first();
$customer->name; // assuming that the model exists, i.e: if ($customer != null) {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.