我想知道是否有办法在许多项目上执行updateOrCreate。
这就是我所拥有的:
foreach ($request->input('inventories') as $group_id => $inventory) {
foreach ($inventory as $inventory_id => $quantity) {
if (is_null($quantity) || $quantity == 0) {
continue;
}
$event->eventInventory()->updateOrCreate([
'group_id' => $group_id,
'inventory_id' => $inventory_id
], [
'quantity' => $quantity ?? 0
]);
}
}
有更好或更清洁的方法吗?