Files
2026-06-15 09:11:57 +07:00

56 lines
2.2 KiB
PHP

<?php
namespace App\Http\Resources\Api\Service\Order;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceDetailResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'service_name' => $this->product?->name ?? $this->server_name,
'server_name' => $this->server_name,
'product_type' => $this->product?->product_type,
'billing_cycle' => $this->orderItem?->billing_cycle,
'status' => $this->status,
'status_text' => $this->status_label,
'auto_renew' => (bool) $this->auto_renew,
'started_at' => $this->started_at?->toISOString(),
'expires_at' => $this->expires_at?->toISOString(),
'note' => $this->note,
'invoice_id' => $this->invoice_id,
'invoice_number' => $this->invoice?->invoice_number,
'product' => $this->whenLoaded('product', fn () => [
'id' => $this->product->id,
'uuid' => $this->product->uuid,
'name' => $this->product->name,
'product_type' => $this->product->product_type,
'specs' => [
'cpu' => $this->product->cpu,
'ram' => $this->product->ram,
'disk' => $this->product->disk,
'bandwidth' => $this->product->bandwidth,
],
]),
'addons' => $this->whenLoaded('addons', fn () => $this->addons->map(fn ($a) => [
'type' => $a->addon_type,
'value' => $a->addon_value,
'price' => $a->price,
])->all()),
'vmware' => $this->whenLoaded('vmware', fn () => $this->vmware ? [
'id' => $this->vmware->id,
'name' => $this->vmware->name,
'hostname' => $this->vmware->hostname,
'ip_address' => $this->vmware->ipAddress?->ip,
'os_name' => $this->vmware->os?->name,
'status' => $this->vmware->status,
'next_due_date' => $this->vmware->next_due_date?->toISOString(),
] : null),
];
}
}