我有一个集合,里面有Eager 加载的嵌套后代(区域模型):
Illuminate\Database\Eloquent\Collection {#1649 ▼
#items: array:1 [▼
0 => App\Models\Region {#1650 ▼
...
#relations: array:1 [▼
"descendants" => Illuminate\Database\Eloquent\Collection {#1646 ▼
#items: array:2 [▼
0 => App\Models\Region {#1660 ▶}
…
#relations: array:1 [▼
"descendants" => Illuminate\Database\Eloquent\Collection {#1657 ▼
#items: array:2 [▼
0 => App\Models\Region {#1672 ▶}
1 => App\Models\Region {#1671 ▶}
]
1 => App\Models\Region {#1659 ▶}
etc …
我想将整个集合展平为同一个类的单个集合,这样新集合中的顺序将如下所示:
Illuminate\Database\Eloquent\Collection {#1676 ▼
#items: array:10 [▼
0 => App\Models\Region {#1650 ▶} (parent)
1 => App\Models\Region {#1660 ▶} (child 1)
2 => App\Models\Region {#1672 ▶} (grandchild 1)
3 => App\Models\Region {#1671 ▶} (grandchild 2)
4 => App\Models\Region {#1659 ▶} (child 2)
etc …
我需要它是一个Eloquent 的模型集合,而不是数组的集合.
提前谢谢!