Its easy with the below package, Just install the package via composer :
https://github.com/spatie/array-to-xml
The implementation will be :
$array= 'invoice' => [
'date' => date('Y-m-d H:i:s'),
'due_date' => date('Y-m-d H:i:s'),
'client' => ['name' => 'John', 'code' => ''],
'items' => [
'item' => [
'name' => 'reg1',
'description' => 'reg1 on evt',
'unit_price' => '10',
'quantity' => '1.0'
],
'item' => [
'name' => 'reg1',
'description' => 'reg1 on evt',
'unit_price' => '10',
'quantity' => '1.0'
]
]
]
And then :
$result = ArrayToXml::convert($array);
Don't forget to include use Spatie\ArrayToXml\ArrayToXml; at the top of the class/Controller.
Its easy with the below package, Just install the package via composer :
https://github.com/spatie/array-to-xml
The implementation will be :
$array= 'invoice' => [
'date' => date('Y-m-d H:i:s'),
'due_date' => date('Y-m-d H:i:s'),
'client' => ['name' => 'John', 'code' => ''],
'items' => [
'item' => [
'name' => 'reg1',
'description' => 'reg1 on evt',
'unit_price' => '10',
'quantity' => '1.0'
],
'item' => [
'name' => 'reg1',
'description' => 'reg1 on evt',
'unit_price' => '10',
'quantity' => '1.0'
]
]
]
And then :
$result = ArrayToXml::convert($array);
Don't forget to include use Spatie\ArrayToXml\ArrayToXml; at the top of the class/Controller.
I recently released a package that helps convert data to valid xml. It is based on Spatie's array to xml package.
You can find it here: https://github.com/mtownsend5512/collection-xml
It has some handy global helpers, such as array_to_xml() and you can convert a collection by doing $collection->toXml().