2
我想從Eloquent(Laravel 4.2)得到結果到簡單的數組中,所以我決定讓array_diff
。Eloquent(Laravel)結果到數組
在文檔中,我發現all()
函數,它給出了數組的結果,但也是我不能擁有的東西,因爲array_diff
。
我:
$curCentres = Doccentre::where('r_document', $document)->select('r_id')->get()->all();
但是這回是這樣的:
array(2) {
[0]=> object(Doccentre)#1125 (20) {
["table":protected]=> string(9)
"doccentre" ["primaryKey":protected]=> string(4)
"r_id" ["timestamps"]=> bool(false)
["connection":protected]=> NULL
["perPage":protected]=> int(15)
["incrementing"]=> bool(true)
["attributes":protected]=> array(1) {
["r_id"]=> string(1) "1"
}
["original":protected]=> array(1) {
["r_id"]=> string(1) "1"
}
["relations":protected]=> array(0) { }
["hidden":protected]=> array(0) { }
["visible":protected]=> array(0) { }
["appends":protected]=> array(0) { }
["fillable":protected]=> array(0) { }
["guarded":protected]=> array(1) {
[0]=> string(1) "*"
}
["dates":protected]=> array(0) { }
["touches":protected]=> array(0) { }
["observables":protected]=> array(0) { }
["with":protected]=> array(0) { }
["morphClass":protected]=> NULL
["exists"]=> bool(true)
}
[1]=> object(Doccentre)#1124 (20) {
["table":protected]=> string(9)
"doccentre" ["primaryKey":protected]=> string(4)
....
}
所有我需要的是:
array(2) { [0]=> string(1) "1" [1]=> string(1) "2" }
有什麼辦法得到它?我也試過toArray()
,但它只會產生錯誤。
你可以使用:https://www.neontsunami.com/posts/diffing-eloquent-collections-in-laravel-4這很酷,因爲你仍然可以擁有你的集合(這是在類固醇的**數組* *)。 –