Download the PHP package chrgriffin/collection-macro-csv without Composer
On this page you can find all versions of the php package chrgriffin/collection-macro-csv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chrgriffin/collection-macro-csv
More information about chrgriffin/collection-macro-csv
Files in chrgriffin/collection-macro-csv
Package collection-macro-csv
Short Description Laravel Collection macro: convert a collection to a CSV-ready array or string.
License MIT
Informations about the package collection-macro-csv
Laravel Collection Macros: CSV
This package will add two Collection macros to transform your Collection into a CSV-ready array or a CSV string, respectively.
Installation
Install in your Laravel project via composer:
If your version of Laravel supports auto-discovery (versions 5.5 and up), that's it!
For older versions of Laravel, you will need to edit your config/app.php
file to include the service provider in your providers array:
Usage
You should now be able to chain ->toCsvArray()
and ->toCsvString
on any Collection.
toCsvArray
->toCsvArray()
will transform a two dimensional Collection of associative arrays into a two dimensional array of 'rows' ready for CSV formatting.
toCsvString
->toCsvString()
will transform a two dimensional Collection of arrays into a CSV string.
You can also pass in a custom delimiter if you need to use something other than a comma:
Inconsistent Columns
For Collections of arrays where the array indexes are not consistent with one another, a default value of null
will be used to 'fill in' missing values:
Structure Requirements
The only requirement is that your Collection contain only arrays. If a non-array value is encountered at the first level of the Collection, a MalformedCollectionException
will be thrown.