PHPackages                             vmporcayom/laravel-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. vmporcayom/laravel-xml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

vmporcayom/laravel-xml
======================

Laravel XML Support with Tramite label

v3.0.0(5y ago)04MITPHPPHP ^7.2.5

Since Jul 2Pushed 4y agoCompare

[ Source](https://github.com/VMPorcayoM/laravel-xml)[ Packagist](https://packagist.org/packages/vmporcayom/laravel-xml)[ Docs](https://github.com/mtvbrianking/laravel-xml)[ RSS](/packages/vmporcayom-laravel-xml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (13)Used By (0)

Laravel XML Support Package
---------------------------

[](#laravel-xml-support-package)

[![](./art/banner.png)](./art/banner.png)

[![Code Quality](https://camo.githubusercontent.com/3dd3cdad8b791b9d7ebab1d4f9af365c383565bd0c038e4b8910cbcc8903295e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d7476627269616e6b696e672f6c61726176656c2d786d6c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mtvbrianking/laravel-xml/?branch=master)[![Code Style](https://camo.githubusercontent.com/25f576ba8528bf48441c6df177f2610037c4765993265373905fcb2618302efe/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3133393332353133312f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/139325131)[![Total Downloads](https://camo.githubusercontent.com/e0ebc319f9b091915c1d0b609bccb72a815ef4a5e21aefadf5d84be90331b52a/68747470733a2f2f706f7365722e707567782e6f72672f626d61746f76752f6c61726176656c2d786d6c2f646f776e6c6f616473)](https://packagist.org/packages/bmatovu/laravel-xml)[![Latest Stable Version](https://camo.githubusercontent.com/1e8fbe7c06e23eaf62637220514f4dffd780044ebb7a004563013a37bee094ae/68747470733a2f2f706f7365722e707567782e6f72672f626d61746f76752f6c61726176656c2d786d6c2f762f737461626c65)](https://packagist.org/packages/bmatovu/laravel-xml)[![License](https://camo.githubusercontent.com/f6035a6b1498daf6ccbb4697b7e18b17316a7cc3d6eb7fd207808c99f5803fa4/68747470733a2f2f706f7365722e707567782e6f72672f626d61746f76752f6c61726176656c2d786d6c2f6c6963656e7365)](https://packagist.org/packages/bmatovu/laravel-xml)[![Documentation](https://github.com/mtvbrianking/laravel-xml/workflows/gen-docs/badge.svg)](https://mtvbrianking.github.io/laravel-xml/master/)

This package comes with the much desired xml support for you Laravel project including middleware to accept only xml requests, http response in xml, and more utilities for xml conversions as well as validation.

**Supports:** Laravel versions v5.3 and above

### Installation

[](#installation)

```
$ composer require bmatovu/laravel-xml
```

### Requests

[](#requests)

Get the request content (body).

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

\* Returns `Bmatovu\LaravelXml\Support\XMLElement` object.

Determine if the request content type is XML.

```
$request->isXml();
```

Determine if the current request is accepting XML.

```
$request->wantsXml();
```

Validate XML content

```
Xml::is_valid($request->xml());
```

**Validation** - Against XML Schema Definition

```
$errors = Xml::validate($request->xml(), 'path_to/sample.xsd');

if ($errors) {
    return response()->xml(['error' => $errors], 422);
}
```

### Responses

[](#responses)

Expects an array, convent you're objects to arrays prior...

```
Route::get('/users', function () {
    $users = App\User::all();
    return response()->xml(['users' => $users->toArray()]);
});
```

Sample response from above snippet

```

        1
        John Doe
        jdoe@example.com
        2018-07-12 17:06:13
        2018-07-12 18:00:05

        2
        Gary Plant
        gplant@example.com
        2018-07-12 18:02:26
        2018-07-13 11:22:44

```

And will automatically set the content type to xml

`Content-Type → text/xml; charset=UTF-8`

### Middleware

[](#middleware)

First register the middleware in `app\Http\Kernel.php`

```
protected $routeMiddleware = [
    // ...
    'xml' => \Bmatovu\LaravelXml\Http\Middleware\RequireXml::class,
];
```

Then use the middleware on your routes, or in the controllers.

```
Route::post('/user/store', function (Request, $request) {
    // do something...
})->middleware('xml');
```

In case of the request `content-type` is not xml, the response will be;

\[`415` - **Unsupported Media Type**\]

```

    Only accepting xml content

```

### Utilities

[](#utilities)

**Encode: Array to Xml**

```
Xml::encode(['key' => 'value']);
```

Or

```
xml_encode(['key' => 'value']);
```

**Decode: Xml to Array**

```
Xml::decode('value');
```

Or

```
xml_decode('value');
```

---

Credits
-------

[](#credits)

Under the hood, I'm using;

[Spatie's array to XML convernsion](https://github.com/spatie/array-to-xml)

[Hakre's XML to JSON conversion](https://hakre.wordpress.com/2013/07/09/simplexml-and-json-encode-in-php-part-i)

[Akande's XML validation](https://medium.com/@Sirolad/validating-xml-against-xsd-in-php-5607f725955a)

Reporting bugs
--------------

[](#reporting-bugs)

If you've stumbled across a bug, please help us by leaving as much information about the bug as possible, e.g.

- Steps to reproduce
- Expected result
- Actual result

This will help us to fix the bug as quickly as possible, and if you do wish to fix it yourself; feel free to [fork the package on GitHub](https://github.com/mtvbrianking/laravel-xml) and submit a pull request!

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.3% 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

Every ~67 days

Recently: every ~125 days

Total

13

Last Release

2067d ago

Major Versions

1.x-dev → v2.0.02020-03-10

v2.0.0 → v3.0.02020-09-13

PHP version history (2 changes)1.0.0PHP &gt;=5.6.4

v2.0.0PHP ^7.2.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bf3cfc76a8c84033aaf90cca4664e04963e61e21fef5366c8d3bb06fdd8499b?d=identicon)[VMPorcayoM](/maintainers/VMPorcayoM)

---

Top Contributors

[![mtvbrianking](https://avatars.githubusercontent.com/u/5412360?v=4)](https://github.com/mtvbrianking "mtvbrianking (65 commits)")[![VMPorcayoM](https://avatars.githubusercontent.com/u/42719730?v=4)](https://github.com/VMPorcayoM "VMPorcayoM (4 commits)")[![Poket-Jony](https://avatars.githubusercontent.com/u/15607518?v=4)](https://github.com/Poket-Jony "Poket-Jony (2 commits)")[![trollfalgar](https://avatars.githubusercontent.com/u/441455?v=4)](https://github.com/trollfalgar "trollfalgar (1 commits)")

---

Tags

responserequestmiddlewarelaravelxmlpackage

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[bmatovu/laravel-xml

Laravel XML Support

91270.4k](/packages/bmatovu-laravel-xml)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[tucker-eric/laravel-xml-middleware

A Laravel Middleware to accept XML requests

181.2M](/packages/tucker-eric-laravel-xml-middleware)[erlandmuchasaj/laravel-gzip

Gzip your responses.

40129.3k2](/packages/erlandmuchasaj-laravel-gzip)[ultrono/laravel-sitemap

Sitemap generator for Laravel 11, 12 and 13

36412.6k6](/packages/ultrono-laravel-sitemap)

PHPackages © 2026

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