Php 为什么展平()对这个集合没有任何影响-流明/拉维?
我已创建以下集合:Php 为什么展平()对这个集合没有任何影响-流明/拉维?,php,laravel,eloquent,orm,lumen,Php,Laravel,Eloquent,Orm,Lumen,我已创建以下集合: $join = coretable::with($permittedTables)->findMany(1); 其中,$permittedTables是一个表名数组 获取的结果如下所示: [{ "id": 1, "Internal_key": "TESTKEY_1", "extensiontable_itc": { "description": "EXTENSION_iTC_1" }, "extensiontable_sysops": {
$join = coretable::with($permittedTables)->findMany(1);
其中,$permittedTables
是一个表名数组
获取的结果如下所示:
[{
"id": 1,
"Internal_key": "TESTKEY_1",
"extensiontable_itc": {
"description": "EXTENSION_iTC_1"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_1"
}
}]
$join = $join->flatten();
我现在想对结果使用展平,如下所示:
[{
"id": 1,
"Internal_key": "TESTKEY_1",
"extensiontable_itc": {
"description": "EXTENSION_iTC_1"
},
"extensiontable_sysops": {
"description": "EXTENSION_SYSOPS_1"
}
}]
$join = $join->flatten();
但是什么也没发生,我甚至没有得到一个错误xD
根据官方文件,这至少会产生一些东西,即使不是预期的结果:
我还尝试通过向其参数传递1或2来手动指定数组的深度,但它没有改变任何内容^^
谁能给我一个暗示我错过了什么
编辑:
以下是$join
的dd()
结果:
^ Illuminate\Database\Eloquent\Collection {#109
#items: array:1 [
0 => App\CoreTable {#112
#table: "coretable"
#fillable: array:1 [
0 => "Internal_key"
]
#hidden: array:2 [
0 => "created_at"
1 => "updated_at"
]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:4 [
"id" => 1
"Internal_key" => "TESTKEY_1"
"created_at" => null
"updated_at" => "2020-02-04 12:34:29"
]
#original: array:4 [
"id" => 1
"Internal_key" => "TESTKEY_1"
"created_at" => null
"updated_at" => "2020-02-04 12:34:29"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:2 [
"extensiontable_itc" => App\extensiontable_itc {#95
#table: "extensiontable_itc"
#hidden: array:4 [
0 => "id"
1 => "coretable_id"
2 => "created_at"
3 => "updated_at"
]
#fillable: array:1 [
0 => "description"
]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:5 [
"id" => 1
"coretable_id" => 1
"description" => "EXTENSION_iTC_1"
"created_at" => null
"updated_at" => null
]
#original: array:5 [
"id" => 1
"coretable_id" => 1
"description" => "EXTENSION_iTC_1"
"created_at" => null
"updated_at" => null
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [
0 => "*"
]
}
"extensiontable_sysops" => App\extensiontable_sysops {#92
#table: "extensiontable_sysops"
#hidden: array:4 [
0 => "ID"
1 => "coretable_id"
2 => "created_at"
3 => "updated_at"
]
#fillable: array:1 [
0 => "description"
]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:3 [
"ID" => 1
"coretable_id" => 1
"description" => "EXTENSION_SYSOPS_1"
]
#original: array:3 [
"ID" => 1
"coretable_id" => 1
"description" => "EXTENSION_SYSOPS_1"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [
0 => "*"
]
}
]
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [
0 => "*"
]
}
]
}
您是否也调用了$join->all()?因为它已经被展平,所以元素是stdClass。您是否也调用了$join->all()?因为它已经被展平,所以元素是stdClass。