public static function boot() { parent::boot(); static::saved(function ($purchaseOrderContent) { $po = PurchaseOrder::find($purchaseOrderContent->order_id); $po->update(["total" => $po->calculateTotal(), "status" => $po->calculateStatus()]); }); }
public static function createWith($vendorId, $items) { if (count($items) > 0) { $order = PurchaseOrder::create(['vendor_id' => $vendorId]); foreach ($items as $item) { PurchaseOrderContent::create(['order_id' => $order->id, 'status' => PurchaseOrderContent::STATUS_PENDING, 'price' => $item->costPrice, 'quantity' => $item->quantity, 'item_vendor_id' => $item->pivot_id]); } return $order; } return null; }