PHPackages                             sascha-steinbrink/laravel-csv-file-seeder - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. sascha-steinbrink/laravel-csv-file-seeder

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

sascha-steinbrink/laravel-csv-file-seeder
=========================================

Seed or export the database from/to csv or zip files.

v1.1.0(6y ago)2191MITPHPCI failing

Since Jun 20Pushed 6y agoCompare

[ Source](https://github.com/sascha-steinbrink/laravel-csv-file-seeder)[ Packagist](https://packagist.org/packages/sascha-steinbrink/laravel-csv-file-seeder)[ Docs](https://github.com/sascha-steinbrink/laravel-csv-file-seeder)[ RSS](/packages/sascha-steinbrink-laravel-csv-file-seeder/feed)WikiDiscussions master Synced yesterday

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

LaravelCsvFileSeeder
====================

[](#laravelcsvfileseeder)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4b780a3fb462a2c4dfbfb1a2ab8e8607975dacd368ddd4283919c169608c312c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7361736368612d737465696e6272696e6b2f6c61726176656c2d6373762d66696c652d7365656465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sascha-steinbrink/laravel-csv-file-seeder)[![Total Downloads](https://camo.githubusercontent.com/c95dcb4ce9d0094bbd5fb58b30c8bcfd956975724dad79dac2938212808919ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7361736368612d737465696e6272696e6b2f6c61726176656c2d6373762d66696c652d7365656465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sascha-steinbrink/laravel-csv-file-seeder)[![Build Status](https://camo.githubusercontent.com/0ef5e3cb5852f40f0cdf821594c6d23a8218177be1ef120bf57f3dc5a93ea6b4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7361736368612d737465696e6272696e6b2f6c61726176656c2d6373762d66696c652d7365656465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/sascha-steinbrink/laravel-csv-file-seeder)[![codecov](https://camo.githubusercontent.com/61381e87c2155373e00773476373d5102ce7d5f055a05ca77a225e53febcaa52/68747470733a2f2f636f6465636f762e696f2f67682f7361736368612d737465696e6272696e6b2f6c61726176656c2d6373762d66696c652d7365656465722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/sascha-steinbrink/laravel-csv-file-seeder)[![StyleCI](https://camo.githubusercontent.com/e9e67eb04dba8d5f0dcec62166e18ef8651208fa861cc8ab3aff041c536f46ea/68747470733a2f2f7374796c6563692e696f2f7265706f732f3139323935343833332f736869656c64)](https://styleci.io/repos/192954833)

This package provides the ability to import or export your database to csv or zip files.

- [Installation](#installation)
- [Usage](#usage)
    - [Available seed options](#available-seed-options)
    - [Available export options](#available-export-options)
    - [Using a different path](#using-a-different-path)
    - [Using a different delimiter](#using-a-different-delimiter)
    - [Using an archive](#using-an-archive)
    - [Only specific files](#only-spcific-files)
    - [Using an encrypted archive](#using-an-encrypted-archive)
    - [Using a connection other than the default](#using-a-connection-other-than-the-default)
- [FAQ](#faq)

This is where your description should go. Take a look at [contributing.md](contributing.md) to see a to do list.

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

[](#installation)

This package can be used in Laravel **5.5** or higher!

Via Composer

```
composer require sascha-steinbrink/laravel-csv-file-seeder
```

> If you want to use zipped files make sure `zip` and `unzip` is installed on your system!

You can publish the configuration file with the following command:

```
php artisan vendor:publish --provider="SaschaSteinbrink\LaravelCsvFileSeeder\LaravelCsvFileSeederServiceProvider" --tag="config"
```

The `config/laravel-csv-file-seeder.php` configuration file contains:

```
return [

    /*
    |--------------------------------------------------------------------------
    | Database connection
    |--------------------------------------------------------------------------
    |
    | The database connection to use for seeding.
    |
    */
    'connection' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Data path
    |--------------------------------------------------------------------------
    |
    | The folder the csv files are located in. It defaults to database/data.
    |
    */
    'data_path' => database_path('data'),

    /*
    |--------------------------------------------------------------------------
    | Delimiter character
    |--------------------------------------------------------------------------
    |
    | The csv delimiter to use for parsing csv fields.
    |
    */
    'delimiter' => ',',

    /*
    |--------------------------------------------------------------------------
    | Enclosure character
    |--------------------------------------------------------------------------
    |
    | The csv enclosure to use for parsing csv fields.
    |
    */
    'enclosure' => '"',

    /*
    |--------------------------------------------------------------------------
    | Escape character
    |--------------------------------------------------------------------------
    |
    | The csv escape to use for parsing csv fields.
    |
    */
    'escape' => '\\',

    /*
    |--------------------------------------------------------------------------
    | Trim csv values
    |--------------------------------------------------------------------------
    |
    | Indicates if any leading or trailing white space should be trimmed
    | from the csv fields.
    |
    */
    'trim_values' => true,

    /*
    |--------------------------------------------------------------------------
    | Insert chunk size.
    |--------------------------------------------------------------------------
    |
    | Set the number of rows to read before an insert query will be executed.
    | This will limit the sql queries fired by the seeder and speed up the
    | performance.
    |
    | NOTE: If you have a large amount of data a small chunk size can cause
    |       the seeder to fail because of the large number of insert queries.
    |
    */
    'insert_chunk_size' => 50,

    /*
    |--------------------------------------------------------------------------
    | Truncate tables
    |--------------------------------------------------------------------------
    |
    | Whether or not the desired tables should be truncated before seeding.
    |
    | NOTE: This will only affect tables where seeder data is available for!
    |       All other tables will be untouched!
    */
    'truncate' => true,

    /*
    |--------------------------------------------------------------------------
    | Foreign key checks
    |--------------------------------------------------------------------------
    |
    | Enable or disable foreign key checks while truncating.
    |
    */
    'foreign_key_checks' => true,

    /*
    |--------------------------------------------------------------------------
    | Files to run by the seeder
    |--------------------------------------------------------------------------
    |
    | The files that should be seeded in the given order.
    |
    | If no files are given all files located in the 'data_path' folder will
    | be seeded in alphabetically order.
    |
    */
    'files'     => [],

    /*
    |--------------------------------------------------------------------------
    | Zipped export
    |--------------------------------------------------------------------------
    |
    | Whether or not export an zip archive containing the csv files.
    |
    */
    'zipped' => false,

    /*
    |--------------------------------------------------------------------------
    | Archive name
    |--------------------------------------------------------------------------
    |
    | The archive name to use for saving.
    |
    */
    'archive_name' => 'db-csv-export.zip',

    /*
    |--------------------------------------------------------------------------
    | Encrypted zip archive
    |--------------------------------------------------------------------------
    |
    | Whether or not the exported zip archive should be password protected.
    |
    */
    'encrypted' => false,

    /*
    |--------------------------------------------------------------------------
    | Encryption password
    |--------------------------------------------------------------------------
    |
    | The password to use when encryption is enabled.
    |
    */
    'encryption_password' => env('CSV_SEEDER_ENCRYPTION_PASSWORD', 'secret'),

    /*
    |--------------------------------------------------------------------------
    | Command specific configurations
    |--------------------------------------------------------------------------
    */
    'commands' => [
        /*
        |--------------------------------------------------------------------------
        | Configuration for the csv:export command
        |--------------------------------------------------------------------------
        */
        'export_csv' => [
            /*
            |--------------------------------------------------------------------------
            | Add column names
            |--------------------------------------------------------------------------
            |
            | Whether or not the csv files should contain the column names in the
            | first row.
            |
            */
            'with_headers' => true,

            /*
            |--------------------------------------------------------------------------
            | Tables to ignore
            |--------------------------------------------------------------------------
            |
            | The tables that should be ignored when creating csv files.
            |
            */
            'except' => [
                'migrations',
                'password_resets'
            ],

            /*
            |--------------------------------------------------------------------------
            | Export chunk size
            |--------------------------------------------------------------------------
            |
            | Set the number of items to be written into the csv file at a time.
            | This will decrease the php memory needed to write the files.
            |
            | NOTE: If you have a large amount of data a small chunk size can cause
            |       the export to fail e.g. out of memory exception.
            |
            */
            'export_chunk_size' => 1000,
        ]
    ]
];
```

Usage
-----

[](#usage)

You can seed or export your database through the console using the following artisan commands:

```
php artisan csv:export
```

```
php artisan csv:seed
```

To seed your database using laravel's `php artisan db:seed` command you have to register the `LaravelCsvFileSeeder::class` in the `database\seeds\DatabaseSeeder::class` class.

```
use SaschaSteinbrink\LaravelCsvFileSeeder\LaravelCsvFileSeeder;
// ...
 public function run()
{
    // $this->call(UsersTableSeeder::class);
    $this->call(LaravelCsvFileSeeder::class);
}
```

> The main difference between those two methods is the flexibility of changing the default values of the configuration file through command options which is only possible with the `php artisan csv:seed` command.

Without any options given or by using the ` php artisan db:seed` command all available commands will use the values from the [config/laravel-csv-file-seeder.php configuration file](config/laravel-csv-file-seeder.php).

The default data path in the config file points to *database/data*. Therefore a call to `php artisan db:seed` or `php artisan csv:seed` would seed all files from the *database/data* directory with an *.csv* extension into the database.

> The csv file names must match the corresponding table names! All csv files where the name does not match any table in the database will be ignored.

> You can debug the output of the commands to see which files were ignored (and other information) by increasing the verbosity level (-v/-vv/-vvv)!

> If you are getting 'Integrity constraint violation' errors while seeding try to disable the foreign key checks either by specifying the `-k false` / `--foreign-key-checks=false` option or by disable them globally in the [config/laravel-csv-file-seeder.php configuration file](config/laravel-csv-file-seeder.php)

The export command `php artisan csv:export` will export all tables (except the ones specified in the config file which are by default *migrations* and *password\_resets*) into *database/data* directory.

To be able to change any of the configuration values you have to publish the configuration file. See the [installation instructions](#installation) to do so.

### Available seed options

[](#available-seed-options)

> Note: This options can only be assigned to the `php artisan csv:seed` command! To change any option for the `php artisan db:seed` command you have to change the values in the configuration file!

OptionDefaultDescription--data-path-pdatabase/dataThe folder the csv files are located in--files-i\[\]The files that should be seeded--delimiter-d','The delimiter character to use for parsing csv fields--enclosure-l'"'The enclosure character to use for parsing csv fields--escape-c'\\'The escape character to use for parsing csv fields--trim-values-mtrueShould trim lead-/trailing white spaces from csv fields--insert-chunk-size-s50The number of rows to read before an insert query is fired--truncate-ttrueTruncate the desired tables before seeding--foreign-key-checks-ktrueEnable/disable foreign key checks while truncating--zipped-zfalseImport data is an archive (zip) file--archive-name-a"db-csv-export.zip"The archive name to import--encrypted-efalseThe import archive is encrypted--connectiondefaultThe database connection to seed--forceForce the operation to run when in production> The `--connection` defaults to the default database connection (`config('database.default')`)

### Available export options

[](#available-export-options)

OptionDefaultDescription--data-path-pdatabase/dataThe folder the csv files should be stored--except-x"migrations,password\_resets"The tables that should be ignored--with-headers-wtrueShould include column names--delimiter-d','The delimiter character to use for parsing csv fields--enclosure-l'"'The enclosure character to use for parsing csv fields--escape-c'\\'The escape character to use for parsing csv fields--export-chunk-size-s100The number of items to be written into the csv file at a time--zipped-zfalseExport data as an archive (zip) file--archive-name-a"db-csv-export.zip"The archive name to use for saving--encrypted-efalseEncrypt the archive--connectiondefaultThe database connection to export> The `--connection` defaults to the default database connection (`config('database.default')`)

### Using a different path

[](#using-a-different-path)

To seed all csv files located in */my/path*:

```
php artisan csv:seed -p "/my/path"
```

To export all tables (except the ones specified in the config file) as csv files into */my/path*:

```
php artisan csv:export -p "/my/path"
```

### Using a different delimiter

[](#using-a-different-delimiter)

To seed all csv files located in */my/path* using a semicolon as delimiter:

```
php artisan csv:seed -p "/my/path" -d ";"
```

To export all tables (except the ones specified in the config file) as csv files into */my/path*using a semicolon as delimiter:

```
php artisan csv:export -p "/my/path" -d ";"
```

### Using an archive file

[](#using-an-archive-file)

> The zip option is **not available on windows**!

To seed the export.zip archive located in */my/path*:

```
php artisan csv:seed -z true -p "/my/path" -a "export"
```

To export all tables (except the ones specified in the config file) into *database/data/**dbExport.zip***:

```
php artisan csv:export -z true -a "dbExport"
```

### Only specific files

[](#only-specific-files)

To import only the *users.csv* file located in *database/data*:

```
php artisan csv:seed -i "users"
```

To import only the *users.csv* file located in */my/other/path*:

```
php artisan csv:seed -i "users" -p "/my/other/path"
```

To export all tables except the *users* table and the *migrations* table to the *database/data* directory:

```
php artisan csv:export -x "migrations,users"
```

### Using an encrypted archive

[](#using-an-encrypted-archive)

> The zip option is **not available on windows**!

When providing the `-e true` or `--encrypt=true` option in combination with the `-z true` or `--zipped=true` option a password prompt will be shown, where you can specify the password to use for encryption.

> The `-e true` or `--encrypt=true` will be ignored when zipping is **not** activated. (Either by setting the option `-z true` / `--zipped=true` or by enabling the *zipped* option in the `config/laravel-csv-file-seeder.php` configuration file.)

To seed the encrypted db-csv-export.zip archive located in */my/path*:

```
php artisan csv:seed -z true -p "/my/path" -e
```

To export all tables into an encrypted */my/path/**encrypted.zip*** archive:

```
php artisan csv:export -z true -x "" -a "encrypted" -e
```

**NOTE**:

> If you want to specify a default encryption password for your project you can add it to your env file using the `CSV_SEEDER_ENCRYPTION_PASSWORD` key.

### Using a connection other than the default

[](#using-a-connection-other-than-the-default)

To seed all csv files located in */my/path* using the database bound to *my-other-db* connection:

```
php artisan csv:seed -p "/my/path" --connection="my-other-db"
```

To export all tables as csv files into */my/path* using the database bound to *my-other-db* connection:

```
php artisan csv:export -p "/my/path" -x "" --connection="my-other-db"
```

> The `-x ""` is set to also include the excepted ones specified in the config file which are by default *migrations* and *password\_resets*

FAQ
---

[](#faq)

Please see the [FAQ](faq.md) for more information.

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [contributing.md](contributing.md) for details and a todolist.

Security
--------

[](#security)

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits
-------

[](#credits)

- [Sascha Steinbrink](https://github.com/sascha-steinbrink)

License
-------

[](#license)

license. Please see the [license file](license.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~59 days

Total

5

Last Release

2281d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/86479b523f50b213b56f4e9eb4cce88c80c8cdf044b8c78534a8b033782ec524?d=identicon)[sascha-steinbrink](/maintainers/sascha-steinbrink)

---

Top Contributors

[![sascha-steinbrink](https://avatars.githubusercontent.com/u/21334746?v=4)](https://github.com/sascha-steinbrink "sascha-steinbrink (14 commits)")

---

Tags

laravelexportcsvseedingseederseedexport-csvseedscsv seedcsv seedercsv seedscsv seeding

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sascha-steinbrink-laravel-csv-file-seeder/health.svg)

```
[![Health](https://phpackages.com/badges/sascha-steinbrink-laravel-csv-file-seeder/health.svg)](https://phpackages.com/packages/sascha-steinbrink-laravel-csv-file-seeder)
```

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M712](/packages/maatwebsite-excel)[jeroenzwart/laravel-csv-seeder

Seed the database with Laravel using CSV files

97395.6k2](/packages/jeroenzwart-laravel-csv-seeder)[flynsarmy/csv-seeder

Allows seeding of the database with CSV files

2561.6M1](/packages/flynsarmy-csv-seeder)[crockett/csv-seeder

Database seeding using CSV files

23173.5k](/packages/crockett-csv-seeder)[bfinlay/laravel-excel-seeder

Seed the database with Laravel using Excel, XLSX, XLS, CSV, ODS, Gnumeric, XML, HTML, SLK files

3944.4k](/packages/bfinlay-laravel-excel-seeder)[highsolutions/laravel-lang-import-export

A Laravel package providing artisan commands to import and export language files from and to CSV.

25292.3k](/packages/highsolutions-laravel-lang-import-export)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
