PHPackages                             asamaru7/iseed - 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. asamaru7/iseed

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

asamaru7/iseed
==============

Generate a new Laravel database seed file based on data from the existing database table.

v2.2.2(9y ago)1961BSD-2-ClausePHPPHP &gt;=5.4.0

Since Sep 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/asamaru7/iseed)[ Packagist](https://packagist.org/packages/asamaru7/iseed)[ RSS](/packages/asamaru7-iseed/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (4)Versions (10)Used By (0)

**Inverse seed generator (iSeed)** is a Laravel package that provides a method to generate a new seed file based on data from the existing database table.

[![Build Status](https://camo.githubusercontent.com/79891d74cc469bcd8102313f0fdbf5add9b02efe233735802b7ba873ad6edca0/68747470733a2f2f7472617669732d63692e6f72672f6f72616e676568696c6c2f69736565642e706e67)](http://travis-ci.org/orangehill/iseed)[![Latest Stable Version](https://camo.githubusercontent.com/b922211dd481d218e3804f952170743a2125a7879a1f0060687f6aeaabc6b3dc/68747470733a2f2f706f7365722e707567782e6f72672f6f72616e676568696c6c2f69736565642f762f737461626c652e706e67)](https://packagist.org/packages/orangehill/iseed) [![Total Downloads](https://camo.githubusercontent.com/f47a3deba2dabf586497c8eaf709183019ad8148d5b285874e9a7a52fbb534d3/68747470733a2f2f706f7365722e707567782e6f72672f6f72616e676568696c6c2f69736565642f646f776e6c6f6164732e706e67)](https://packagist.org/packages/orangehill/iseed)[![Analytics](https://camo.githubusercontent.com/e45db5d49eb0ac94f4883add42b4286cdf2692a323f83d2535752ad1f7cae8e9/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d313933363436302d33352f69736565643f757365526566657272657226666c6174)](https://github.com/igrigorik/ga-beacon)

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

[](#installation)

1. Add `orangehill/iseed` to your composer file.

#### Laravel 5

[](#laravel-5)

For Laravel 5 installation edit your project's `composer.json` file to require `orangehill/iseed`.

```
"require": {
	"orangehill/iseed": "dev-master"
}

```

#### Laravel 5 versions less than 5.3.8

[](#laravel-5-versions-less-than-538)

For Laravel 5 versions that are less than 5.3.8 edit your project's `composer.json` file to require `2.2` version:

```
"require": {
	"orangehill/iseed": "2.2"
}

```

#### Laravel 4

[](#laravel-4)

If you wish to install it on Laravel 4 you should require `1.1` version:

```
"require": {
	"orangehill/iseed": "1.1"
}

```

2. Update Composer from the CLI:

    composer update
3. Add the service provider by opening a `app/config/app.php` file, and adding a new item to the `providers` array.

    Orangehill\\Iseed\\IseedServiceProvider::class

Artisan command options
-----------------------

[](#artisan-command-options)

### \[table\_name\]

[](#table_name)

Mandatory parameter which defines which table/s will be used for seed creation. Use CSV notation for multiple tables. Seed file will be generated for each table.

Examples:

```
php artisan iseed my_table

```

```
php artisan iseed my_table,another_table

```

### force

[](#force)

Optional parameter which is used to automatically overwrite any existing seeds for desired tables

Example: The following command will overwrite `UsersTableSeeder.php` if it already exists in laravel's seeds directory.

```
php artisan iseed users --force

```

### dumpauto

[](#dumpauto)

Optional boolean parameter that controls the execution of `composer dump-autoload` command. Defaults to true.

Example that will stop `composer dump-autoload` from execution:

```
php artisan iseed users --dumpauto=false

```

### clean

[](#clean)

Optional parameter which will clean `app/database/seeds/DatabaseSeeder.php` before creating new seed class.

Example:

```
php artisan iseed users --clean

```

### database

[](#database)

Optional parameter which specifies the DB connection name.

Example:

```
php artisan iseed users --database=mysql2

```

### max

[](#max)

Optional parameter which defines the maximum number of entries seeded from a specified table. In case of multiple tables, limit will be applied to all of them.

Example:

```
artisan iseed users --max=10

```

### exclude

[](#exclude)

Optional parameter which accepts comma separated list of columns that you'd like to exclude from tables that are being exported. In case of multiple tables, exclusion will be applied to all of them.

Example:

```
artisan iseed users --exclude=id
artisan iseed users --exclude=id,created_at,updated_at

```

### prerun

[](#prerun)

Optional parameter which assigns a laravel event name to be fired before seeding takes place. If an event listener returns `false`, seed will fail automatically. You can assign multiple preruns for multiple table names by passing an array of comma separated DB names and respectively passing a comma separated array of prerun event names.

Example: The following command will make a seed file which will fire an event named 'someEvent' before seeding takes place.

```
artisan iseed users --prerun=someEvent

```

The following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed before seeding.

```
artisan iseed users,groups --prerun=someUserEvent,someGroupEvent

```

The following example will only assign a `someGroupEvent` to `groups` table seed, to be executed before seeding. Value for the users table prerun was omitted here, so `users` table seed will have no prerun event assigned.

```
artisan iseed users,groups --prerun=,someGroupEvent

```

### postrun

[](#postrun)

Optional parameter which assigns a laravel event name to be fired after seeding takes place. If an event listener returns `false`, seed will be executed, but an exception will be thrown that the postrun failed. You can assign multiple postruns for multiple table names by passing an array of comma separated DB names and respectively passing a comma separated array of postrun event names.

Example: The following command will make a seed file which will fire an event named 'someEvent' after seeding was completed.

```
artisan iseed users --postrun=someEvent

```

The following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed after seeding.

```
artisan iseed users,groups --postrun=someUserEvent,someGroupEvent

```

The following example will only assign a `someGroupEvent` to `groups` table seed, to be executed after seeding. Value for the users table postrun was omitted here, so `users` table seed will have no postrun event assigned.

```
artisan iseed users,groups --postrun=,someGroupEvent

```

Usage
-----

[](#usage)

To generate a seed file for your users table simply call: `\Iseed::generateSeed('users', 'connectionName', 'numOfRows');`. `connectionName` and `numOfRows` are not required arguments.

This will create a file inside a `/database/seeds` (`/app/database/seeds` for Laravel 4), with the contents similar to following example:

```
