【发布时间】:2018-03-02 16:49:53
【问题描述】:
我有两种不同类型的集合。
Collection {#277 ▼
#items: array:2 [▼
"" => Collection {#271 ▼
#items: array:2 [▼
0 => {#265 ▼
+"id": 3
+"name": "Product 3"
+"cover_image": ""
}
1 => {#273 ▼
+"id": 9
+"name": "Product 9"
+"cover_image": ""
}
]
}
1 => Collection {#272 ▼
#items: array:1 [▼
0 => SuperProducts {#282 ▼
+timestamps: true
#table: "super_products"
#fillable: array:6 [▶]
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:9 [▶]
#original: array:9 [▶]
#casts: []
#dates: []
#dateFormat: null
#appends: []
#events: []
#observables: []
#relations: []
#touches: []
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
]
}
]
}
第一个集合是一个数组转换为集合,没有使用 Eloquent。其次是超级产品系列。两个集合使用合并组合在一起。有没有办法可以按类型对这两个不同的集合进行分组?或者也许有更好的解决方案?
【问题讨论】:
标签: laravel laravel-5 collections eloquent