0
我的要求:如何從一個雄辯的請求訪問受保護的屬性
$ipam = Ipam::with('Customer')->where('id','=', x)->take(1)->first();
我有一個很難搞清楚如何訪問來人與我IPAM要求客戶屬性。包含屬性的數組受到保護,所以我無法訪問它們。
我可以用
$ipam->getOriginal();
方法訪問IPAM表的原始屬性,但遺憾的是不返回任何客戶屬性(這是可以預料的)的。
我已經嘗試通過Model文檔查找並沒有發現任何可幫助我訪問客戶屬性的內容。
任何提示將不勝感激。
相關信息:
IPAM模型類:
class Ipam extends Eloquent
{
public function container() {
return $this->belongsToMany('Container');
}
public function customer() {
return $this->hasOne('Customer','customer_id','customer_id');
}
}
顧客模型類:
class Customer extends Eloquent
{
protected $primaryKey = 'customer_id';
public function nets() {
return $this->hasMany('Ipam');
}
}
從查詢響應數據(I去除空字段和數據,以減少雜波):
object(Ipam)#444 (26) {
["table":protected]=>
string(8) "ipam_net"
["primaryKey":protected]=>
string(2) "id"
["perPage":protected]=>
int(15)
["incrementing"]=>
bool(true)
["attributes":protected]=>
array(12) {
["id"]=>
int(x)
["customer_id"]=>
int(SomeId)
/*******************
Some more table data
*******************/
}
["original":protected]=>
array(12) {
["id"]=>
int(x)
["customer_id"]=>
int(SomeId)
/*******************
Some more table data
*******************/
}
["relations":protected]=>
array(1) {
["Customer"]=>
object(Customer)#446 (26) {
["table":protected]=>
string(8) "customer"
["primaryKey":protected]=>
string(11) "customer_id"
["perPage":protected]=>
int(15)
["incrementing"]=>
bool(true)
["attributes":protected]=>
array(14) {
["customer_id"]=>
int(SomeId)
["customer_name"]=>
string(27) "SomeCustomerName"
/*******************
Some more table data
*******************/
}
["original":protected]=>
array(14) {
["customer_id"]=>
int(SomeId)
["customer_name"]=>
string(27) "SomeCustomerName"
/*******************
Some more table data
*******************/
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["exists"]=>
bool(true)
}
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
["exists"]=>
bool(true)
}
你的意思是'$ ipam-> customer-> getOriginal()'不工作嗎?請發佈您的代碼失敗。也可以嘗試將Ipam :: with('Customer')'改爲'Ipam :: with('customer')',使其與屬性名完全匹配。 – PaePae
這是問題所在。我沒有使用正確的語法。 應該像你所建議的'$ ipam-> customer-> getOriginal()'一樣寫它。 我試圖使用'$ ipam-> customer-> toArray()'總是返回'null' –