toArray()) ->mapWithKeys(fn ($value, $key) => [snake_case($key) => $value]) ->toArray(); $response[$node->getUpdatedAtColumn()] = $this->formatTimestamp($node->updated_at); $response[$node->getCreatedAtColumn()] = $this->formatTimestamp($node->created_at); $resources = $node->servers()->select(['memory', 'disk', 'cpu'])->get(); $response['allocated_resources'] = [ 'memory' => $resources->sum('memory'), 'disk' => $resources->sum('disk'), 'cpu' => $resources->sum('cpu'), ]; return $response; } /** * Return the nodes associated with this location. */ public function includeAllocations(Node $node): Collection|NullResource { if (!$this->authorize(Allocation::RESOURCE_NAME)) { return $this->null(); } $node->loadMissing('allocations'); return $this->collection( $node->getRelation('allocations'), $this->makeTransformer(AllocationTransformer::class), 'allocation' ); } /** * Return the nodes associated with this location. */ public function includeServers(Node $node): Collection|NullResource { if (!$this->authorize(Server::RESOURCE_NAME)) { return $this->null(); } $node->loadMissing('servers'); return $this->collection( $node->getRelation('servers'), $this->makeTransformer(ServerTransformer::class), 'server' ); } }