PHPackages                             lanin/laravel-extend-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. [Framework](/categories/framework)
4. /
5. lanin/laravel-extend-seeder

ActiveLibrary[Framework](/categories/framework)

lanin/laravel-extend-seeder
===========================

Extension for Laravel seeder. Seed your database with CSV data.

0.2.0(9y ago)81.5k1MITPHPPHP &gt;=5.6.0

Since Jul 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mlanin/laravel-extend-seeder)[ Packagist](https://packagist.org/packages/lanin/laravel-extend-seeder)[ RSS](/packages/lanin-laravel-extend-seeder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (12)Used By (0)

Laravel-Extend-Seeder
=====================

[](#laravel-extend-seeder)

[![Travis](https://camo.githubusercontent.com/2153735c8c243fef07c1f8b8a6167f61103ff825c4a3649c7ce1ff5e216f18a4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6c616e696e2f6c61726176656c2d657874656e642d7365656465722e737667)](https://travis-ci.org/mlanin/laravel-extend-seeder)

> Extend Laravel seeder and populate your DB with CSV data.

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

[](#installation)

[PHP](https://php.net) 5.4+ or [HHVM](http://hhvm.com) 3.3+, [Composer](https://getcomposer.org) and [Laravel](http://laravel.com) 5.0+ are required.

To get the latest version of Laravel-Extend-Seeder, simply add the following line to the require block of your `composer.json` file.

```
"lanin/laravel-extend-seeder": "dev-master"

```

You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated.

Once it was installed you don't have to register any ServiceProvider, Facade or publish any configs.

All you have to do is to extend your base Seeder class with `\Lanin\ExtendSeeder\Seeder` and you are good to go!

```
class Seeder extends \Lanin\ExtendSeeder\Seeder { }
```

Preparing
---------

[](#preparing)

Every time you try to seed lots of data, you have to unguard your models. Now you don't have to do it. They will be unguarded automatically in the boot method, that fires right on the start. Also it will disable query log, that extremely slows data import.

### Environment protection

[](#environment-protection)

If you are afraid to corrupt your production database with seeding it with test data, even if artisan asks you if you want to do it, you can specify `protected $environment` variable in your seeder. Boot method will check if current environment doesn't match the set one and throw an exception, so you can be sure you don't break your production data.

Seeding
-------

[](#seeding)

After you extended your base seeder, you will receive two additional methods

#### seedModel($model)

[](#seedmodelmodel)

The best place for this method is the `run` method of your main DatabaseSeeder.

By default you have to fire `call` method that will resolve a specified seeder as `{$tableName}TableSeeder` and launch it, and there resolve your models and do all the stuff.

This method will do it for you. It will find related seeder by model's table and pass your model to it.

**Hint:** This method returns resolved seeder object, so you can chain your seed methods.

**Example:**

```
class Account extends \Illuminate\Database\Eloquent\Model {
	protected $table = 'accounts';
}

class DatabaseSeeder extends Seeder {

	/**
	 * Seed your database.
	 */
	public function run()
	{
		$this->seedModel(\App\Account::class);
	}
}

class AccountsTableSeeder extends Seeder {

	/**
	 * Seed model.
	 */
	public function run()
	{
		$this->getModel()->truncate();
	}
}
```

#### seedWithCsv($csvFile = '', $model = null)

[](#seedwithcsvcsvfile---model--null)

This method seeds your database with data from the related csv files.

By default, it tries to find them in your `/database/seeds/csv` directory.

Files have to be names as `{$databaseName}_{$tableName}.csv`, but you can always overwrite this behaviour.

> Note! If you are using the same seeds to seed mysql and sqlite databases (ie. while testing), you have to define your database name manually, or Seeder will try to find csv files like `database.sqlite_your_table.csv`. You can do it via `\Lanin\ExtendSeeder\Seeder::setDatabaseName('database_name');` method.

If you are calling this method via table seeder, that was called via `seedModel`, it already knows everything about your model and can resolve related csv file iteslf.

**Example:**

```
class AccountsTableSeeder extends Seeder {

	/**
	 * Seed model with CSV.
	 */
	public function run()
	{
		$this->seedWithCsv();
	}
}
```

Full example you can find in the `tests/CsvSeederTest.php`

Hacks
-----

[](#hacks)

You can leave TableSeeders empty and chain csv import via basic seeder.

```
class DatabaseSeeder extends Seeder {

	/**
	 * Seed your database.
	 */
	public function run()
	{
		$this->seedModel(\App\Account::class)->seedWithCsv();
	}
}

class AccountsTableSeeder extends Seeder {

	/**
	 * Seed model.
	 */
	public function run()
	{

	}
}
```

You don't even have to create TableSeeders and seed right in your basic seeder.

```
class DatabaseSeeder extends Seeder {

	/**
	 * Seed your database.
	 */
	public function run()
	{
		$this->setModel(\App\Account::class)->seedWithCsv();
	}
}
```

If you want to have your csv files to be set in another location you can use static method `setCsvPath($csvPath)`, where you can specify relative from your base\_path path.

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

[](#contributing)

Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~66 days

Recently: every ~34 days

Total

11

Last Release

3301d ago

Major Versions

0.1.7 → 5.3.x-dev2017-05-05

0.2.0 → 5.4.x-dev2017-05-05

PHP version history (2 changes)0.1PHP &gt;=5.4.0

0.2.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/968784dc2366d12ce2bd6e0b7beaa7ab3cd65ae526401f7840c057c51f5687fe?d=identicon)[lanin](/maintainers/lanin)

---

Top Contributors

[![mlanin](https://avatars.githubusercontent.com/u/467159?v=4)](https://github.com/mlanin "mlanin (25 commits)")

---

Tags

frameworklaravelcsvextensionseeding

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lanin-laravel-extend-seeder/health.svg)

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

###  Alternatives

[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[graham-campbell/markdown

Markdown Is A CommonMark Wrapper For Laravel

1.3k7.1M64](/packages/graham-campbell-markdown)[graham-campbell/manager

Manager Provides Some Manager Functionality For Laravel

39221.1M134](/packages/graham-campbell-manager)[laravel-lang/publisher

Localization publisher for your Laravel application

2167.7M24](/packages/laravel-lang-publisher)[laravel-zero/framework

The Laravel Zero Framework.

3371.4M369](/packages/laravel-zero-framework)[lanin/laravel-api-debugger

Easily debug your JSON API.

2311.8M](/packages/lanin-laravel-api-debugger)

PHPackages © 2026

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