Skip to content
A Formatter Class for Laravel 4 based on FuelPHP's Formatter Class
Branch: master
Clone or download
#51 Compare This branch is 89 commits ahead of studiofrenetic:master.
Jaspaul Merge pull request #47 from ResuBaka/46
Fixed problem for composer require
Latest commit af93de2 Jun 27, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests Added delimiter to CSV Jan 31, 2018
.gitignore Cleaning house for v2.0 Oct 19, 2014
.travis.yml Do not allow failures on PHP7.2 Feb 23, 2018
composer.json Merge pull request #47 from ResuBaka/46 Jun 27, 2018
phpunit.xml updated to put on Sep 20, 2013 Added delimiter to CSV Jan 31, 2018


  • Update composer.json
  • Upgrade to PSR-4
  • add parameter newline, delimiter, enclosure, and escape to export csv
  • When converting a XML to an array, convert @attributes to attribute
  • add parameter encoding and formated to export xml
  • JSON parse fix (Instead of only converting the first level to array, use the associative array parameter with true, so all levels will be decoded to array structure)
  • Add support for laravel 5
  • add package discovery for laravel 5
  • add support delimiter to a csv

Formatter Bundle

Build Status

A formatter package that will help you to easily convert between various formats such as XML, JSON, CSV, etc...


The goals of this library are to allow the transfomation of data formats from one type to another. See Parsers and Formats to see supported input / output formats.


Through command line:

composer require soapbox/laravel-formatter

Through composer.json:

  "require": {
    "soapbox/laravel-formatter": "2.x"


All of the following are supported formats that the formatter can read from.

  • Array
  • CSV
  • JSON
  • XML
  • YAML


All of the following are formats that are supported for output.

  • Array
  • CSV
  • JSON
  • XML
  • YAML

General Usage

Including The Formatter

use SoapBox\Formatter\Formatter;

Supported Types

Formatter::JSON; //json
Formatter::CSV;  //csv
Formatter::XML;  //xml
Formatter::ARR;  //array
Formatter::YAML; //yaml

Making Your First Formatter(s)

$formatter = Formatter::make($jsonString, Formatter::JSON);
$formatter = Formatter::make($yamlString, Formatter::YAML);
$formatter = Formatter::make($array, Formatter::ARR);

Outputting From Your Formatter

$csv   = $formatter->toCsv();
$json  = $formatter->toJson();
$xml   = $formatter->toXml();
$array = $formatter->toArray();
$yaml  = $formatter->toYaml();

Deprecated Functionality

The following have been deprecated from the library, however you can easily continue using them in your application

Serialized Array

$serialized = serialize($formatter->toArray());

PHP Export

$export = var_export($formatter->toArray());
You can’t perform that action at this time.