PHP code example of mtownsend / request-xml

1. Go to this page and download the library: Download mtownsend/request-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 / request-xml example snippets


/*
 * Package Service Providers...
 */
Mtownsend\RequestXml\Providers\RequestXmlServiceProvider::class,

$app->register(Mtownsend\RequestXml\Providers\RequestXmlServiceProvider::class);

protected $middleware = [
    \Mtownsend\RequestXml\Middleware\XmlRequest::class,
];

protected $middlewareGroups = [
    'web' => [
        \Mtownsend\RequestXml\Middleware\XmlRequest::class,
    ],
];

protected $middlewareGroups = [
    'api' => [
        \Mtownsend\RequestXml\Middleware\XmlRequest::class,
    ],
];

protected $routeMiddleware = [
    'xml' => \Mtownsend\RequestXml\Middleware\XmlRequest::class,
];

if (request()->wantsXml()) {
    // send xml response
}

if (request()->isXml()) {
    // do something
}

$data = request()->xml();

$xml = (object) request()->xml();

$xml = collect(request()->xml());

if ($exception instanceof \Mtownsend\RequestXml\Exceptions\CouldNotParseXml) {
    // do something
}