src/Traits/ExportsCollection.php
public function toXML(Builder $query)
    {
        $root = with($dom = new DOMDocument())->createElement('root');

        foreach ($this->each($query) as $object) {
            $item = $dom->createElement('item');

            foreach ($this->toScalar($object) as $column => $value) {
                $column = $dom->createElement($column, htmlspecialchars($value));
                $item->appendChild($column);
            }

            $root->appendChild($item);
        }

        $dom->appendChild($root);

        file_put_contents(
            $file = $this->getFilename(),
            $dom->saveXML()
        );

        return $this->sendDownloadResponse($file, 'xml', ['Content-Type' => 'text/xml']);
    }
public function toXML(Builder $query)
    {
        $root = with($dom = new DOMDocument())->createElement('root');

        foreach ($this->each($query) as $object) {
            $item = $dom->createElement('item');

            foreach ($this->toScalar($object) as $column => $value) {
                $column = $dom->createElement($column, htmlspecialchars($value));
                $item->appendChild($column);
            }

            $root->appendChild($item);
        }

        $dom->appendChild($root);

        file_put_contents(
            $file = $this->getFilename(),
            $dom->saveXML()
        );

        return $this->sendDownloadResponse($file, 'xml', ['Content-Type' => 'text/xml']);
    }
public function toXML ( Builder $ query ) { $ root = with ( $ dom = new DOMDocument ( ) ) -> createElement ( 'root' ) ; foreach ( $ this -> each ( $ query ) as $ object ) { $ item = $ dom -> createElement ( 'item' ) ; foreach ( $ this -> toScalar ( $ object ) as $ column => $ value ) { $ column = $ dom -> createElement ( $ column , htmlspecialchars ( $ value ) ) ; $ item -> appendChild ( $ column ) ; } $ root -> appendChild ( $ item ) ; } $ dom -> appendChild ( $ root ) ; file_put_contents ( $ file = $ this -> getFilename ( ) , $ dom -> saveXML ( ) ) ; return $ this -> sendDownloadResponse ( $ file , 'xml' , [ 'Content-Type' => 'text/xml' ] ) ; }
Convert & download collection in XML format.

@param $query

@return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
Convert & download collection in XML format .