PHPackages                             martijnvreeken/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. [Database &amp; ORM](/categories/database)
4. /
5. martijnvreeken/laravel-xml

ActiveLibrary[Database &amp; ORM](/categories/database)

martijnvreeken/laravel-xml
==========================

Convert Eloquent models to XML, as well as normal objects.

2.0.0(6y ago)0111MITPHPPHP &gt;=7.0.0

Since Jul 4Pushed 6y ago1 watchersCompare

[ Source](https://github.com/martijnvreeken/laravel-xml)[ Packagist](https://packagist.org/packages/martijnvreeken/laravel-xml)[ Docs](https://github.com/martijnvreeken/laravel-xml)[ RSS](/packages/martijnvreeken-laravel-xml/feed)WikiDiscussions master Synced today

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

LaravelXML
==========

[](#laravelxml)

> Never manipulate XML again! (Hopefully.)

***Please note*: LaravelXML may have some issues. Feel free to open pull requests!**

*This package is aimed at the [Laravel Framework](https://laravel.com). A standalone version may be created at some point.*

Ever tried to convert various types of values to XML? Perhaps you need to make an "export as XML" feature. If you have, then you probably know that XML can be an absolute *pain in the butt*.

**LaravelXML** aims to solve this problem. Easily modify *how* and *when* it will convert objects. You can even write your own code to extend it! How cool is that?

If you use XML in your app, LaravelXML is a good choice for you!

Prerequisites
-------------

[](#prerequisites)

To use LaravelXML, there are not really any specific prerequisites. Just make sure you have the `xml` PHP extension installed! You can check to see if you have it by running `php -i | grep xml` and seeing if anything comes back. If nothing shows up after running that command, you need to install the XML extension.

You also must have PHP 7.0 or above.

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

[](#installation)

Installation is quick and easy. All you have to do is run

```
composer require fetchleo/laravel-xml dev-master

```

*Currently, there is not a stable release. I'm going to work on the tests some more and avoid tagging a release until I'm sure everything works.*

Once that is complete, be sure to register the package's service provider in your `config/app.php` by adding this line:

```
FetchLeo\LaravelXml\XmlServiceProvider::class

```

There's nothing else you really need to do! Of course, you can always modify the configuration, which will be covered below.

Configuration
-------------

[](#configuration)

If you would like to publish the LaravelXML configuration file, simply run

```
php artisan vendor:publish --tag=laravel-xml

```

Usage
-----

[](#usage)

Out of the box, LaravelXML should work just fine! No need to set any weird settings right away. Unless, of course, you like doing that sort of thing, in which case, read on.

### Converting Values

[](#converting-values)

LaravelXML comes with a quick way to convert values to XML. Please note that due to certain limitations, there are certain types of values that can **NOT** be converted by themselves. However, they can be inside of other values that CAN be converted.

These non-self-convertable types are:

- Integers (or doubles/floats)
- Strings

That means that unless they are inside a different value, one that CAN be converted (an array, etc), they can not be converted. So, calling `Xml::convert(1)` would throw an exception. **This will be changed soon! You will be able to specify your *OWN* converters for these types. Default ones may be provided as well.**

Anyway, moving on from that...

To convert a value to XML, simply call `Xml::convert($value)`, being sure to import `FetchLeo\LaravelXml\Facades\Xml`. Under the hood, LaravelXML is attempting to locate an appropriate converter for the value. If no suitable one is found, an exception will be thrown. You can specify and create your own converters; read on to find out how!

### Custom Converters

[](#custom-converters)

In addition to the converters that come out of the box, you can create your own converters.

First, you should create a new class that implements the `FetchLeo\LaravelXml\Contracts\Converter` interface.

It should look something like this:

```
