resource->relationLoaded('products')) { foreach ($this->resource->products as $product) { $product->setRelation('order', $this->resource); } } return [ 'id' => $this->id, 'sn' => $this->sn, 'products' => OrderProductResource::collection($this->whenLoaded('products')), 'coupon_discount_amount' => $this->coupon_discount_amount_format, 'vip_discount_amount' => $this->vip_discount_amount_format, 'reduced_amount' => $this->reduced_amount_format, 'shipping_fee' => $this->shipping_fee_format, 'products_total_amount' => $this->products_total_amount_format, 'total_amount' => $this->total_amount_format, 'status' => $this->order_status, 'note' => (string) $this->note, 'consignee_name' => $this->consignee_name, 'consignee_telephone' => $this->consignee_telephone, 'consignee_zone' => $this->consignee_zone, 'consignee_address' => $this->consignee_address, 'pay_way' => (string) $this->pay_way, 'pay_at' => (string) $this->pay_at?->toDateTimeString(), 'completed_at' => (string) $this->completed_at?->toDateTimeString(), 'created_at' => $this->created_at->toDateTimeString(), 'expires_at' => $this->expires_at, 'packages' => OrderPackageResource::make($this->whenLoaded('lastPackage')), ]; } }