post('topic', '')); $payload = $request->post('payload', ''); $qos = (int) $request->post('qos', 1); $retain = filter_var($request->post('retain', false), FILTER_VALIDATE_BOOL); if (is_array($payload)) { $payload = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR); } $traceId = MqttPublisher::publish($topic, (string) $payload, $qos, $retain); return $this->success(['trace_id' => $traceId], 'MQTT message queued.'); } catch (\Throwable $exception) { return $this->fail($exception->getMessage()); } } }