PHPackages                             metawesome/laravel-request-xml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. metawesome/laravel-request-xml

ActiveLibrary[API Development](/categories/api)

metawesome/laravel-request-xml
==============================

The missing XML support for Laravel's Request class.

1.0.0(6y ago)0521MITPHPPHP ~7.0

Since Jul 9Pushed 6y agoCompare

[ Source](https://github.com/meta-awesome/xml-request)[ Packagist](https://packagist.org/packages/metawesome/laravel-request-xml)[ RSS](/packages/metawesome-laravel-request-xml/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

The missing XML support for Laravel's Request class.

This package is designed to work with the [Laravel](https://laravel.com) framework.

Installation
------------

[](#installation)

Install via composer:

```
composer require Meta/request-xml

```

### Registering the service provider

[](#registering-the-service-provider)

For Laravel 5.4 and lower, add the following line to your `config/app.php`:

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

For Laravel 5.5 and greater, the package will auto register the provider for you.

### Using Lumen

[](#using-lumen)

To register the service provider, add the following line to `app/bootstrap/app.php`:

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

### Middleware

[](#middleware)

It's important to register the middleware so your application can convert an XML request and merge it into the Request object. You will then be able to run XML through Laravel's powerful validation system.

**Please note:**

Once you register the middleware, you do not need to do anything special to access your request xml. It will be available in the Request object like it would if it was a json or form request.

To setup the middleware, open up your `app/Http/Kernel.php` file.

To add the middleware globally:

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

To add the middleware to web routes only:

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

To add the middleware to api routes only:

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

Or, if you want named middleware for specific routes:

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

Quick start
-----------

[](#quick-start)

### Determine if the request wants an xml response

[](#determine-if-the-request-wants-an-xml-response)

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

### Determine if the request contains xml

[](#determine-if-the-request-contains-xml)

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

### Get the converted xml as an array

[](#get-the-converted-xml-as-an-array)

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

Methods
-------

[](#methods)

**Request method**

`->wantsXml()`

Works very similar to Laravel's `->wantsJson()` method by returning a boolean. It will tell you if the incoming request would like to receive an XML response back.

**Request method**

`->isXml()`

Returns a boolean. This will tell you if the incoming request is XML.

**Request method**

`->xml()`

Returns an array. This converts the XML request into a PHP array. You are free to cast it to an object:

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

Or wrap it in a collection:

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

Exceptions
----------

[](#exceptions)

In the event invalid XML is received in a request, the application will throw an Exception containing the raw, invalid XML. If you would like to handle this exception whenever it occurs in your application, you can easily catch it and supply your own code in your applications `app/Exceptions/Handler.php` like so:

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

Testing
-------

[](#testing)

You can run the tests with:

```
./vendor/bin/phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2496d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/349028befa840be702b5b7dae5b08b1fc02c5e1a24aca7e270cd4943b1f5d833?d=identicon)[metawesome](/maintainers/metawesome)

---

Top Contributors

[![dieigson-nadalon](https://avatars.githubusercontent.com/u/202655257?v=4)](https://github.com/dieigson-nadalon "dieigson-nadalon (9 commits)")

---

Tags

requestapilaravelxmlisXmlwantsXml

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/metawesome-laravel-request-xml/health.svg)

```
[![Health](https://phpackages.com/badges/metawesome-laravel-request-xml/health.svg)](https://phpackages.com/packages/metawesome-laravel-request-xml)
```

###  Alternatives

[mtownsend/request-xml

The missing XML support for Laravel's Request class.

43432.5k](/packages/mtownsend-request-xml)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[mtownsend/response-xml

The missing XML support for Laravel's Response class.

1041.2M3](/packages/mtownsend-response-xml)[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
