xitude's avatar

Converting JSON (Array) to XML

Hi Laracasters, I'm looking to convert my array's to XML for google products XML feeds.

I'm tried a few packages but nothing is really useful. I'm unsure if just writing a forloop with xml elements, but this to me sounds silly as I'm sure there is someway to convert it simply in Laravel (Lumen).

Tanks in advance.

0 likes
3 replies
xitude's avatar
xitude
OP
Best Answer
Level 2

I ended up just using a view that had a forloop around the data. Used a response in the controller that told the view what content-type it needed and it outputted correctly so no need for a package.

But ill take a look at it now anywhos.

$products = Product::all();
        $content = view('product.xml', compact('products'));

        return response($content, 200)
            ->header('Content-Type', 'text/xml');
1 like

Please or to participate in this conversation.