Download the PHP package quince/data-importer without Composer
On this page you can find all versions of the php package quince/data-importer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download quince/data-importer
More information about quince/data-importer
Files in quince/data-importer
Package data-importer
Short Description Tool for importing data from tabular data files into laravel models
License MIT
Informations about the package data-importer
data-importer
Tool for importing data from tabular data files into laravel models
Installation
Add data-importer to your composer.json file.
for laravel 4:
and for laravel 5:
Use composer to install this package.
Registering the Package
Register the service provider within the providers array found in app/config/app.php
:
Configuration
Next step is to publish package configuration by running:
in laravel 4 run:
and in laravel 5 run:
Config file could be found in app/config/packages/quince/data-importer/config.php
for laravel 4 and in config/quince/data-importer.php
Usage
You can use data-importer in two ways
Using Laravel IoC Container
Make sure exporter service manager is registered in your app config.
Using Laravel Dependency Injection
You can also inject Quince\DataImporterManager
in your class, and use it.
Advanced Usages
Each row of file is a presenter of a record in database, and each record may have relation records.
In your csv file, a column may be present these relation records.
Header of this column is a concatenation of relation name and field name of relation that is provide in that column
(Concat with relation_joint
is set in config file).
if a column have many relation records, values should be separated with relation_value_delimiter
which is set in config file.
Example
The file below:
name | username | phones.number | |
---|---|---|---|
John Doe | Johny | [email protected] | 0941120773 |
Jane Doe | Jane6 | [email protected] | 0929339687|0916740160 |
will be converted to something like this (as json):
Additional Fields
When only some of the table fields are provided in given file, you can set those field manualy
NOTE: You should specify additional fields are for main record or relation records
If fields that specified as additional fields
exist in csv file, data will be loaded from csv file.
But if you pass true
as second parameter for setAdditionalFields
aditional fields will overwrite existing data in csv file.
Translating file headers
When column headers of your file are defferent from your table columns, you can map them to your database table columns. Assume your file is like:
Real Name | Nickname | Mail Address | Phone Numbers |
---|---|---|---|
John Doe | Johny | [email protected] | 0941120773 |
Jane Doe | Jane6 | [email protected] | 0929339687|0916740160 |
you can pass a dictionary for your file custom header to translate them to their table-column names.
you can also map a single column of your file to a column in your database table.
For more information about advanced usage visit wiki pages
Config file
field | description | default value |
---|---|---|
delimiter | The character is used to separate each column in a row. | , |
enclosure | The character is used to specify the enclosure. | " |
escape | The character to escape invalid characters. | \ |
chunk_size | The size of rows to be processed by closure you pass to import method. | 100 |
relation_joint | The character to join relation name and column of relation table you want to import. | . |
relation_value_delimiter | The character to delimit relation value from each other. | \| |
All versions of data-importer with dependencies
illuminate/support Version ~4.0
illuminate/database Version ~4.0
illuminate/config Version ~4.0
league/csv Version ~6.0