如何将 Xml 输出到文件?
How can I make a Xml output to file?
我有一个 xml 输出。我将数组转换为 xml。但是如何将此输出转换为文件呢?我需要将此文件存储在我的存储文件夹中,因为我想在需要时下载它。想象一下这样的事情:
鉴于我们有 table
然后我们将table数据转换为xml。
然后它应该存储为 xml 文件
当我们按下按钮时
它应该作为 xml 文件下载。
我需要最后 3 个步骤才能让它正常工作。非常感谢..
我认为这应该足以完成您的任务。
来自 laravel 文档:
@Aleksandrs 回答后我明白了。问题解决了。
我做了类似的事情。
public function downloadXml($filename = '')
{
$fields = ['created_at', 'updated_at'];
$products = Product::where('user_id', auth()->id())->exclude($fields)->get()->toArray();
$products = array_collapse($products);
// dd($products);
$result = ArrayToXml::convert($products, 'product');
Storage::put(auth()->id().'File/products.xml', $result);
}
我有一个 xml 输出。我将数组转换为 xml。但是如何将此输出转换为文件呢?我需要将此文件存储在我的存储文件夹中,因为我想在需要时下载它。想象一下这样的事情:
鉴于我们有 table
然后我们将table数据转换为xml。
然后它应该存储为 xml 文件
当我们按下按钮时
它应该作为 xml 文件下载。
我需要最后 3 个步骤才能让它正常工作。非常感谢..
我认为这应该足以完成您的任务。
来自 laravel 文档:
@Aleksandrs 回答后我明白了。问题解决了。
我做了类似的事情。
public function downloadXml($filename = '')
{
$fields = ['created_at', 'updated_at'];
$products = Product::where('user_id', auth()->id())->exclude($fields)->get()->toArray();
$products = array_collapse($products);
// dd($products);
$result = ArrayToXml::convert($products, 'product');
Storage::put(auth()->id().'File/products.xml', $result);
}