Php – Creating default object from empty value in YII2
Code that causes problem foreach ($items as $itemData) { $item = new PurchaseItem(); $item->internal_product_id = (int)$itemData['internal_product_id']; $item->quantity = (float)$itemData['quantity']; $item->total = (float)$itemData['total']; $item->purchase_id = $purchase->id; if (!$item->save()) { throw new Exception('Error saving the purchase item.'); } } Table Structure CREATE…