Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Laravel Formatter

soapbox/laravel-formatter image

Laravel Formatter stats

Downloads
903.2K
Stars
249
Open Issues
15
Forks
93

View on GitHub →

A formatting library that converts data output between XML, CSV, JSON, TXT, YAML and a few others.

Changelog

  • Update support for Laravel 6 & phpunit 8
  • 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

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

Goals

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.

Installation

Through command line:

composer require soapbox/laravel-formatter

Through composer.json:

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

Parsers

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

  • Array
  • CSV
  • JSON
  • XML
  • YAML

Formats

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());
Soapbox photo

Helping managers and employees have better meetings, one byte at a time.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Soapbox Laravel Formatter Related Articles

JSON Alexander Gives Developers a Simpler, More Trustworthy Way to View JSON in the Browser image

JSON Alexander Gives Developers a Simpler, More Trustworthy Way to View JSON in the Browser

Read article
Livewire 4 Support in Laravel VS Code Extension v1.4.3 image

Livewire 4 Support in Laravel VS Code Extension v1.4.3

Read article
Docker Support in Laravel VS Code Extension v1.4.2 image

Docker Support in Laravel VS Code Extension v1.4.2

Read article
PHP DebugBar v3 is released image

PHP DebugBar v3 is released

Read article
PrettyPHP is an opinionated code formatter for PHP image

PrettyPHP is an opinionated code formatter for PHP

Read article
Repeat Strings Efficiently with Laravel's Str::repeat Method image

Repeat Strings Efficiently with Laravel's Str::repeat Method

Read article
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell