无法使用数组 laravel 更新我的库存表

问题描述 投票:0回答:1

我有一个要更新到库存表的数据数组列表。

              $data['items'] = DB::table('inventory_items')->select('inventory_items.*')
                ->join('sorder_parts', 'inventory_items.id', 'sorder_parts.inventory_id')
                ->where('sorder_parts.sorder_id', '=', $id)
                ->selectraw('inventory_items.quantity - sorder_parts.quantity AS new_quantity')
                ->get()->toArray();

            foreach ($data as $product_item) {
                $reduce_quantity = InventoryItem::updateOrCreate(['id' => $product_item['items']['id']],
                ['quantity' => $product_item['quantity']['new_quantity']]);      
            }
laravel database function migration schema
1个回答
0
投票

可能 $product_item 变量没有 items 键。尝试将“$product_item['items']['id']”更改为“$product_item['id']”。

因为带有 get() 方法的“DB”门面不会返回深层数组。

© www.soinside.com 2019 - 2024. All rights reserved.