title: Trying to return XML with laravel. wrong parse xml
body: <p>Hi im trying to make a xml file with laravel 5.2.</p>
  
  <p>My function What i commented out i tried, wrong xml parse.</p>
  
  <pre><code>    public function createXML() {
          $maps = Maps::get()-&gt;toArray();
  
  //        function array_to_xml(array $arr, SimpleXMLElement $xml)
  //        {
  //            foreach ($arr as $k =&gt; $v) {
  //                is_array($v)
  //                    ? array_to_xml($v, $xml-&gt;addChild($k))
  //                    : $xml-&gt;addChild($k, $v);
  //            }
  //            return $xml;
  //        }
          function to_xml(SimpleXMLElement $object, array $data)
          {
              foreach ($data as $key =&gt; $value) {
                  if (is_array($value)) {
                      $new_object = $object-&gt;addChild($key);
                      to_xml($new_object, $value);
                  } else {
                      $object-&gt;addChild($key, $value);
                  }
              }
          }
  
  //        $xmloutput = to_xml($maps, new SimpleXMLElement('&lt;root/&gt;'))-&gt;asXML();
          $xml = new SimpleXMLElement('&lt;rootTag/&gt;');
          to_xml($xml, $maps);
  
          return Response::make($xml-&gt;asXML())-&gt;header('Content-Type', 'text/xml');
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HpIso.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HpIso.png" alt="enter image description here"></a></p>
  
  <p>my output array:</p>
  
  <pre><code>array:2 [▼
    0 =&gt; array:5 [▼
      "id" =&gt; 1
      "name" =&gt; "Leeuwarden"
      "address" =&gt; "Leeuwarden"
      "lat" =&gt; 53.20132
      "lng" =&gt; 5.80005
    ]
    1 =&gt; array:5 [▼
      "id" =&gt; 2
      "name" =&gt; "Assen"
      "address" =&gt; "Assen"
      "lat" =&gt; 52.99275
      "lng" =&gt; 6.56423
    ]
  ]
  </code></pre>
  
  <p>Any suggestions on what i am doing wrong?</p>
  
  <p>i'm trying to make a google maps API map with pointers from the database.</p>