PHPackages                             flabib/laravel-csv-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. flabib/laravel-csv-seeder

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

flabib/laravel-csv-seeder
=========================

Seed the database with Laravel using CSV files

v1.2.4(6y ago)08MITPHPPHP &gt;=5.4.0

Since Sep 28Pushed 6y agoCompare

[ Source](https://github.com/Flabib/laravel-csv-seeder)[ Packagist](https://packagist.org/packages/flabib/laravel-csv-seeder)[ Docs](https://github.com/Flabib/laravel-csv-seeder)[ RSS](/packages/flabib-laravel-csv-seeder/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (9)Used By (0)

Laravel CSV Seeder
==================

[](#laravel-csv-seeder)

> #### Seed your database using CSV files with Laravel
>
> [](#seed-your-database-using-csv-files-with-laravel)

With this package you can save time for seeding your database. Instead of typing out the seeder files, you can use CSV files to fill up the database of your project. There are configuration options available to control the insert the data of your CSV files.

### Features

[](#features)

- Automatically try to resolve CSV filename to table name.
- Automatic mapping of CSV headers to table column names.
- Skip seeding data with a prefix at in the CSV headers.
- Hash values with a given array of column names.
- Seed default values in to table columns.
- Adjust Laravel's timestamp at seeding.

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

[](#installation)

- Require this package directly by `composer require --dev Flabib/laravel-csv-seeder`
- Or add this package in your composer.json and run `composer update`

    "Flabib/laravel-csv-seeder": "1.\*"

Basic usage
-----------

[](#basic-usage)

Extend your seed classes with `Flabib\CsvSeeder\CsvSeeder` and set the variable `$this->file` with the path of the CSV file. Tablename is not required, if the filename of the CSV is the same as the tablename. At last call `parent::run()` to seed. A seed class will look like this;

```
use Flabib\CsvSeeder\CsvSeeder;

class UsersTableSeeder extends CsvSeeder
{
    public function __construct()
    {
        $this->file = '/database/seeds/csvs/users.csv';
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        // Recommended when importing larger CSVs
	    DB::disableQueryLog();
	    parent::run();
    }
}
```

Place your CSV into the path */database/seeds/csvs/* of your Laravel project or whatever path you specify in the constructor. As default the given CSV require a header row with names, matching the columns names of the table in your database. Looks like this;

```
first_name,last_name,birthday
Foo,Bar,1970-01-01
John,Doe,1980-01-01

```

Configuration
-------------

[](#configuration)

- `tablename` *(string*) - Name of table to insert data.
- `truncate` *(boolean TRUE)* - Truncate the table before seeding.
- `header` *(boolean TRUE)* - CSV has a header row, set FALSE if not.
- `mapping` *(array \[\])* - Associative array of column names in order as CSV, if empy the first row of CSV will be used as header.
- `aliases` *(array \[\])* - Associative array of CSV header names and column names; csvColumnName =&gt; aliasColumnName.
- `skipper` *(string %)* - Skip a CSV header and data to import in the table.
- `validate` *(array \[\])* - Validate a CSV row with Laravel Validation.
- `hashable` *(array \['password'\])* - Array of column names to hash there values. It uses Hash::make().
- `defaults` *(array \[\])* - Array of table columns and its values to seed with CSV file.
- `timestamps` *(string/boolean TRUE)* - Set Laravel's timestamp in the database while seeding; set as TRUE will use current time.
- `delimiter` *(string ;)* - The used delimiter in the CSV files.
- `chunk` *(integer 50)* - Insert the data of rows every `chunk` while reading the CSV.
- `encode` *(boolean TRUE)* - Encode the value of rows to UTF-8

Tip
---

[](#tip)

Users of Microsoft Excel can use a macro to export there worksheets to CSV. Easiest is to name your worksheets as table name. Use the following macro to export;

```
Public Sub SaveWorksheetsAsCsv()
ActiveWorkbook.Save
Dim xWs As Worksheet
Dim xDir As String
Dim folder As FileDialog
Set folder = Application.FileDialog(msoFileDialogFolderPicker)
If folder.Show  -1 Then Exit Sub
xDir = folder.SelectedItems(1)
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.SaveAs xDir & "\" & xWs.Name, xlCSV
Next
End Sub

```

Examples
--------

[](#examples)

#### Table with given timestamps

[](#table-with-given-timestamps)

Give the seeder a specific table name instead of using the CSV filename;

```
	public function __construct()
    	{
		$this->file = '/database/seeds/csvs/users.csv';
		$this->tablename = 'email_users';
		$this->timestamps = '1970-01-01 00:00:00';
	}
```

#### Mapping

[](#mapping)

Map the CSV headers to table columns, with the following CSV;

```
1,Foo,Bar
2,John,Doe

```

Handle like this;

```
	public function __construct()
	{
		$this->file = '/database/seeds/csvs/users.csv';
		$this->mapping = ['id', 'firstname', 'lastname'];
		$this->header = FALSE;
	}
```

#### Aliases with defaults

[](#aliases-with-defaults)

Seed a table with aliases and default values, like this;

```
	public function __construct()
	{
		$this->file = '/database/seeds/csvs/users.csv';
		$this->aliases = ['csvColumnName' => 'table_column_name', 'foo' => 'bar'];
		$this->defaults = ['created_by' => 'seeder', 'updated_by' => 'seeder'];
	}
```

#### Skipper

[](#skipper)

Skip a column in a CSV with a prefix. For example you use `id` in your CSV and only usable in your CSV editor. The following CSV file looks like so;

```
%id,first_name,last_name,%id_copy,birthday
1,Foo,Bar,1,1970-01-01
2,John,Doe,2,1980-01-01

```

The first and fourth value of each row will be skipped with seeding. The default prefix is '%' and changeable to;

```
	public function __construct()
	{
		$this->file = '/database/seeds/csvs/users.csv';
		$this->skipper = 'custom_';
	}
```

#### Validate

[](#validate)

Validate each row of a CSV like this;

```
	public function __construct()
	{
		$this->file = '/database/seeds/csvs/users.csv';
		$this->validate = [ 'name'              => 'required',
                            'email'             => 'email',
                            'email_verified_at' => 'date_format:Y-m-d H:i:s',
                            'password'          => ['required', Rule::notIn([' '])]];
	}
```

#### Hash

[](#hash)

Hash values when seeding a CSV like this;

```
	public function __construct()
	{
		$this->file = '/database/seeds/csvs/users.csv';
		$this->hashable = ['password', 'salt'];
	}
```

License
-------

[](#license)

Laravel CSV Seeder is open-sourced software licensed under the MIT license.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~70 days

Recently: every ~89 days

Total

8

Last Release

2292d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e676b7352bb924bd2f6f597611c90dd22f7bbdfe7873d75cbc43a0091dcd31c5?d=identicon)[Flabib](/maintainers/Flabib)

---

Top Contributors

[![jeroenzwart](https://avatars.githubusercontent.com/u/7695208?v=4)](https://github.com/jeroenzwart "jeroenzwart (20 commits)")[![Flabib](https://avatars.githubusercontent.com/u/18245138?v=4)](https://github.com/Flabib "Flabib (1 commits)")[![jozef-b](https://avatars.githubusercontent.com/u/22389945?v=4)](https://github.com/jozef-b "jozef-b (1 commits)")[![petersowah](https://avatars.githubusercontent.com/u/6297425?v=4)](https://github.com/petersowah "petersowah (1 commits)")[![Roboonl](https://avatars.githubusercontent.com/u/12096210?v=4)](https://github.com/Roboonl "Roboonl (1 commits)")[![TheGeremy](https://avatars.githubusercontent.com/u/271762637?v=4)](https://github.com/TheGeremy "TheGeremy (1 commits)")

---

Tags

laravelexcelcsvseedingseederseedseeds

### Embed Badge

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

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

###  Alternatives

[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)[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)

PHPackages © 2026

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