PHPackages                             pmatseykanets/artisan-io - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pmatseykanets/artisan-io

ActiveLibrary[Database &amp; ORM](/categories/database)

pmatseykanets/artisan-io
========================

Artisan data import command for Laravel

v3.0.0(5y ago)172.0k3MITPHPPHP ^7.2CI failing

Since Jul 22Pushed 5y ago2 watchersCompare

[ Source](https://github.com/pmatseykanets/artisan-io)[ Packagist](https://packagist.org/packages/pmatseykanets/artisan-io)[ RSS](/packages/pmatseykanets-artisan-io/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (0)

artisan-io
==========

[](#artisan-io)

[![StyleCI](https://camo.githubusercontent.com/ecc7a9107e0a0ec9c23e8c19740d447be345b63ea2fefcb1f3444c711a9c862d/68747470733a2f2f7374796c6563692e696f2f7265706f732f33393330373530392f736869656c64)](https://styleci.io/repos/39307509)[![tests](https://github.com/pmatseykanets/artisan-io/workflows/tests/badge.svg)](https://github.com/pmatseykanets/artisan-io/workflows/tests/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/68d616a250688a14307e92efed4420d24b520671d55d42d579f49d79c03647e0/68747470733a2f2f706f7365722e707567782e6f72672f706d61747365796b616e6574732f6172746973616e2d696f2f762f737461626c65)](https://packagist.org/packages/pmatseykanets/artisan-io)[![License](https://camo.githubusercontent.com/5b2ed4179f7fd586ab6e22d2aa9059d13c82aaa4867569b0bf882e7acd8c37fc/68747470733a2f2f706f7365722e707567782e6f72672f706d61747365796b616e6574732f6172746973616e2d696f2f6c6963656e7365)](https://packagist.org/packages/pmatseykanets/artisan-io)

This package adds data import capability to your [Laravel](http://laravel.com/) 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`](http://laravel.com/docs/8.x/database#introduction)).
- 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](http://laravel.com/docs/8.x/eloquent-mutators).
- Import modes:
    - insert
    - insert-new
    - update
    - upsert
- Row validation rules

If you find this package usefull, please consider bying me a coffee.

[![Buy Me a Coffee at ko-fi.com](https://camo.githubusercontent.com/154f15d832baabe75153bc6f3f3923cdd4eda07ed77efd80d92544ee1c381ddf/68747470733a2f2f63646e2e6b6f2d66692e636f6d2f63646e2f6b6f6669322e706e673f763d32)](https://ko-fi.com/V7V43MXAO)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require pmatseykanets/artisan-io
```

If you're using Laravel &lt; 5.5 or if you have package auto-discovery turned off you have to manually register the service provider:

```
// config/app.php
'providers' => [
    ...
    ArtisanIo\ArtisanIoServiceProvider::class,
],
```

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

```
protected $commands = [
    \ArtisanIo\Console\ImportDelimitedCommand::class,
];
```

Usage
-----

[](#usage)

```
php artisan import:delimited --help

Usage:
  import:delimited [options] [--]

Arguments:
  from                           The path to an import file i.e. storage/import.csv
  to                             The table or Eloquent model class name

Options:
  -f, --fields[=FIELDS]          A comma separated list of field definitions in a form [:position] i.e. "email:0,name,2". Positions are 0 based
  -F, --field-file[=FIELD-FILE]  Path to a file that contains field definitions. One definition per line
  -m, --mode[=MODE]              Import mode [insert|insert-new|update|upsert] [default: "upsert"]
  -k, --key[=KEY]                Field names separated by a comma that constitute a key for update, upsert and insert-new modes
  -R, --rule-file[=RULE-FILE]    Path to a file that contains field validation rules
  -d, --delimiter[=DELIMITER]    Field delimiter [default: ","]
  -i, --ignore[=IGNORE]          Ignore first N lines of the file
  -t, --take[=TAKE]              Take only M lines
  -c, --database[=DATABASE]      The database connection to use
  -x, --transaction              Use a transaction
      --dry-run                  Dry run mode
      --no-progress              Don't show the progress bar
      --force                    Force the operation to run when in production
```

Examples
--------

[](#examples)

Lets say we have `employee.csv` file

```
email,firstname,lastname,employed_on,phone
john.doe@example.com,John,Doe,07/01/2014,2223334455
jane.doe@example.com,Jane,Doe,02/15/2015,5554443322

```

table `employee` the migration for which may look like

```
Schema::create('employees', function (Blueprint $table) {
    $table->increments('id');
    $table->string('email')->unique();
    $table->string('firstname', 60)->nullable();
    $table->string('lastname', 60)->nullable();
    $table->string('phone', 10)->nullable();
    $table->date('employed_on')->nullable();
    $table->timestamps();
});
```

and model `\App\Employee`

```
