title: How to store and return results from MQTT callback function? PHP - Laravel
body: <p>I have installed a <code>PHP</code> library for <code>MQTT</code> from this <a href="https://github.com/php-mqtt/client" rel="nofollow noreferrer">link.</a></p>
  <p>Now I want to use it within an ajax call performed with <code>axios</code> to retrieve data from a broker. So I followed an example and created the controller <code>MqttController@KreirajMqtt</code>:</p>
  <pre><code>public function KreirajMqtt()
  {
      $server = 'mqtt3.thingspeak.com';
      $port = 1883;
      $username = 'myUsername';
      $clientId = 'myId';
      $password = 'myPassword';
  
      $mttq = new MqttClient($server, $port, $clientId);
  
      $connectionSettings = new ConnectionSettings();
      $connectionSettings
          -&gt;setUsername($username)
          -&gt;setPassword($password)
          -&gt;setKeepAliveInterval(15)
          -&gt;setLastWillTopic('channels/myChannel/subscribe')
          -&gt;setLastWillMessage('client disconnect')
          -&gt;setLastWillQualityOfService(0);
  
      $mttq-&gt;connect($connectionSettings, true);
  
      $mttq-&gt;subscribe(
          'channels/myChannel/subscribe',
          function ($topic, $message) {
              echo sprintf(&quot;Received message on topic [%s]: %s\n&quot;, $topic, $message);
          },
          0
      );
  }
  </code></pre>
  <p>How can I change this so that it returns the data retrieved via MQTT to my frontend where I want to display it using Vue.js?</p>