map(function (Node $node) { $latest = NetworkMetric::where('node_id', $node->id) ->orderByDesc('recorded_at') ->first(); return [ 'id' => $node->id, 'name' => $node->name, 'fqdn' => $node->fqdn, 'rx_bytes' => $latest?->rx_bytes ?? 0, 'tx_bytes' => $latest?->tx_bytes ?? 0, 'recorded_at'=> $latest?->recorded_at, ]; }); return response()->json(['data' => $nodes]); } /** GET api/application/addons/network/nodes/{node} */ public function show(Node $node): JsonResponse { $metrics = NetworkMetric::where('node_id', $node->id) ->orderByDesc('recorded_at') ->limit(60) ->get(['recorded_at', 'rx_bytes', 'tx_bytes', 'server_id']); return response()->json([ 'node' => ['id' => $node->id, 'name' => $node->name, 'fqdn' => $node->fqdn], 'metrics' => $metrics, ]); } }