【发布时间】:2019-09-15 21:50:21
【问题描述】:
我正在尝试将缺失值添加到导致我的数据库表包含多个项目的集合中。
我试图尝试将集合中缺少的项目添加为联合值。
Collection {#217 ▼
#items: array:7 [▼
0 => {#397 ▼
+"item_id": 1
+"amount": "4"
}
1 => {#402 ▼
+"item_id": 3
+"amount": "1"
}
2 => {#396 ▶}
3 => {#213 ▶}
4 => {#399 ▶}
5 => {#400 ▶}
6 => {#398 ▶}
]
}
我使用了 union 但它不起作用,它创建了一个单独的数组
$union = $collection->union([2 => ['0']]);
我不想要单独的数组和重复项。
【问题讨论】:
标签: mysql laravel laravel-5 collections