resolveBusiness($request); if (! $business) { return $this->jsonError('Business not found.', 404); } return $this->jsonSuccess([ 'devices' => IotDevice::where('business_id', $business->id)->get(), 'open_alerts' => IotAlert::where('business_id', $business->id) ->where('status', 'open') ->latest('id') ->limit(20) ->get(), ]); } public function ingest(Request $request, IotIngestionService $ingestion) { $business = $this->resolveBusiness($request); if (! $business) { return $this->jsonError('Business not found.', 404); } $validated = $request->validate([ 'device_uid' => 'required|string', 'readings' => 'required|array', 'readings.*.metric' => 'required|string', 'readings.*.value' => 'required|numeric', ]); $ingestion->ingest((int) $business->id, $validated['device_uid'], $validated['readings']); return $this->jsonSuccess(null, 'Telemetry ingested.'); } }