Files
portal-api/app/Http/Resources/Api/Client/Service/ServiceClientDetailResource.php
T

61 lines
2.0 KiB
PHP

<?php
namespace App\Http\Resources\Api\Client\Service;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ServiceClientDetailResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if (!$this->resource) {
return [];
}
$orderItem = $this->orderItem;
$order = $orderItem?->order;
$vm = $order?->vmWare?->first();
$product = $orderItem?->product;
return [
'uuid' => $this->uuid,
'server_name' => $this->server_name,
'status' => $this->status,
'auto_renew' => $this->auto_renew,
'started_at' => $this->started_at?->toISOString(),
'expires_at' => $this->expires_at?->toISOString(),
'os' => [
'version' => $orderItem?->os?->version,
'group' => $orderItem?->os?->osGroup?->name,
],
'specs' => $product ? [
'cpu' => (int) ($product->cpu ?? 0),
'ram' => (int) ($product->ram ?? 0),
'disk' => (int) ($product->disk ?? 0),
'bandwidth' => (int) ($product->bandwidth ?? 0),
] : null,
'order' => $order ? [
'total' => (float) $order->total,
'months' => (int) $orderItem->months,
'billing_label' => $orderItem->billing_label,
] : null,
'vm' => $vm ? [
'id' => $vm->id,
'vmware_id' => $vm->vmware_id,
'ip_address' => $vm->ipAddress?->ip,
'hostname' => $vm->hostname,
'username' => $vm->user,
'password' => $vm->getRawOriginal('password'),
'port' => $vm->port,
'status' => $vm->status,
] : null,
];
}
}