PHP code example of mtownsend / response-xml

1. Go to this page and download the library: Download mtownsend/response-xml library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mtownsend / response-xml example snippets


/*
 * Package Service Providers...
 */
Mtownsend\ResponseXml\Providers\ResponseXmlServiceProvider::class,

$app->register(Mtownsend\ResponseXml\Providers\ResponseXmlServiceProvider::class);

$data = [
    'status' => 'success',
    'data' => [
        'first_name' => 'John',
        'last_name' => 'Smith',
    ]
];
return response()->xml($data);

// Returns:
<?xml version="1.0"

return response()->xml(User::all());

$xml = <<<XML
<?xml version="1.0"

$data = [
    'status' => 'success',
    'data' => [
        'first_name' => 'John',
        'last_name' => 'Smith',
    ]
];
return response()->preferredFormat($data);