get(['id AS order_id', 'product_ids', 'agent_id', 'agent_product_id']); foreach ($ids as $v) { $item = Product::query()->whereIn('id', explode(',', $v['product_ids'])) ->orderBy('id')->get(['id AS product_id', 'supplier_id'])->toArray(); foreach ($item as $v2) { if (!OrderProductItem::query()->where(['order_id' => $v['order_id'], 'product_id' => $v2['product_id']])->exists()) { $v2['order_id'] = $v['order_id']; $v2['agent_id'] = $v['agent_id']; $v2['agent_product_id'] = $v['agent_product_id']; OrderProductItem::query()->create($v2); } } } return ''; } }