Download the PHP package pmatseykanets/artisan-io without Composer
On this page you can find all versions of the php package pmatseykanets/artisan-io. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package artisan-io
artisan-io
This package adds data import capability to your Laravel project. It contains an artisan command import:delimited
which allows you, as the name implies, to import delimited data (CSV, TSV, etc) into your local or remote database.
Main features:
- Supports multiple database connections (defined in
config\database.php
). - You can use either a table name or Eloquent model class to import your data. By using Eloquent model you can benefit from mutators and accessors.
- Import modes:
- insert
- insert-new
- update
- upsert
- Row validation rules
If you find this package usefull, please consider bying me a coffee.
Installation
You can install the package via composer:
If you're using Laravel < 5.5 or if you have package auto-discovery turned off you have to manually register the service provider:
Alternatively you can register the command yourself
Open app\Console\Kernel.php
in the editor of your choice and add the command to the $commands
array
Usage
Examples
Lets say we have employee.csv
file
table employee
the migration for which may look like
and model \App\Employee
Insert
If employees
table is empty and you'd like to populate it
Note: The buity of using Eloquent model in this case is that timestamps created_at
and updated_at
will be populated by Eloquent automatically.
Upsert
Now let's assume John's record is already present in the table. In order to update Jon's record and insert Jane's one you'd need to cnahge the mode and specify key field(s).
Update
If you want to just update phone numbers for existing records
Field definition file
Each field definition goes on a separate line in the format
<fieldname>[:position]
where position
is an ordinal position of the field in the data file. The position is 0-based and can be omitted.
Example employee.fld
Row validation rules file
A row validation rule file is simply a php file that returns an array of rules. You can any of the available Laravel validation rules
Example employee.rule
License
The artisan-io is open-sourced software licensed under the MIT license
All versions of artisan-io with dependencies
illuminate/support Version ~6.0|~7.0|~8.0
illuminate/container Version ~6.0|~7.0|~8.0
illuminate/database Version ~6.0|~7.0|~8.0
illuminate/validation Version ~6.0|~7.0|~8.0
illuminate/config Version ~6.0|~7.0|~8.0
illuminate/console Version ~6.0|~7.0|~8.0