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

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

leuzeus/iseed
=============

This is a fork of the SchuBu/iseed of the original package Orangehill/Iseed. Generate a new Laravel database seed file based on data from the existing database table.

v4.0.6(1y ago)0416BSD-2-ClausePHPPHP ^7.2|^8.0.2

Since Oct 29Pushed 1y agoCompare

[ Source](https://github.com/LeuZeuS/iseed)[ Packagist](https://packagist.org/packages/leuzeus/iseed)[ RSS](/packages/leuzeus-iseed/feed)WikiDiscussions main Synced 1mo ago

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

\*\*This is another fork of  (fork of [orangehill/iseed](https://github.com/orangehill/iseed) with updated few things and added iseed:all command)

**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/7c2823104a6c9e5a1fa58a3b3785beea0889a339fea1bbbf6785b8d8b4697482/68747470733a2f2f7472617669732d63692e6f72672f5363687542752f69736565642e706e67)](http://travis-ci.org/SchuBu/iseed)[![Latest Stable Version](https://camo.githubusercontent.com/5521006390ba777e3fd6ff7279641e80baadc8fd4f616708589565331ec163fa/68747470733a2f2f706f7365722e707567782e6f72672f5363687542752f69736565642f762f737461626c652e706e67)](https://packagist.org/packages/SchuBu/iseed) [![Total Downloads](https://camo.githubusercontent.com/aad6e42fb5426e9b06f43b16ea58647be617b6f74c0b42026fc5bdbe97a21e48/68747470733a2f2f706f7365722e707567782e6f72672f5363687542752f69736565642f646f776e6c6f6164732e706e67)](https://packagist.org/packages/SchuBu/iseed)[![Analytics](https://camo.githubusercontent.com/e45db5d49eb0ac94f4883add42b4286cdf2692a323f83d2535752ad1f7cae8e9/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d313933363436302d33352f69736565643f757365526566657272657226666c6174)](https://github.com/igrigorik/ga-beacon)

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

[](#installation)

### 1. Require with [Composer](https://getcomposer.org/)

[](#1-require-with-composer)

```
$ composer require SchuBu/iseed
```

**Laravel 5.3.7 and below** or **Laravel 4** need specific version.

```
$ composer require SchuBu/iseed:2.2 # Laravel 5.3.7 and below
$ composer require SchuBu/iseed:1.1 # Laravel 4
```

### 2. Add Service Provider (Laravel 5.4 and below)

[](#2-add-service-provider-laravel-54-and-below)

Latest Laravel versions have auto dicovery and automatically add service provider - if you're using 5.4.x and below, remember to add it to `providers` array at `/app/config/app.php`:

```
// ...
SchuBu\Iseed\IseedServiceProvider::class,
```

Artisan Commands
----------------

[](#artisan-commands)

Iseed comes with two artisan commands:

1. `php artisan iseed`
2. `php artisan iseed:all`

### php artisan iseed

[](#php-artisan-iseed)

```
$ php artisan iseed --help
Description:
  Generate seed file from table

Usage:
  iseed [options] [--]

Arguments:
  tables                                   comma separated string of table names

Options:
      --clean                              clean iseed section
      --force                              force overwrite of all existing seed classes
      --database[=DATABASE]                database connection [default: "mysql"]
      --max[=MAX]                          max number of rows
      --chunksize[=CHUNKSIZE]              size of data chunks for each insert query
      --exclude[=EXCLUDE]                  exclude columns
      --prerun[=PRERUN]                    prerun event name
      --postrun[=POSTRUN]                  postrun event name
      --dumpauto[=DUMPAUTO]                run composer dump-autoload [default: true]
      --noindex                            no indexing in the seed
      --orderby[=ORDERBY]                  orderby desc by column
      --direction[=DIRECTION]              orderby direction
      --classnameprefix[=CLASSNAMEPREFIX]  prefix for class and file name
      --classnamesuffix[=CLASSNAMESUFFIX]  suffix for class and file name
```

### php artisan iseed:all

[](#php-artisan-iseedall)

```
$ php artisan iseed:all --help
Description:
  Generate seed files for all tables except migrations

Usage:
  iseed:all [options]

Options:
      --force
```

Artisan Command Options
-----------------------

[](#artisan-command-options)

The primary artisan command (`php artisan iseed`) contains a series of arguments (some required, some optional) you can use when calling the command.

### \[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
```

### classnameprefix &amp; classnamesuffix

[](#classnameprefix--classnamesuffix)

Optionally specify a prefix or suffix for the Seeder class name and file name. This is useful if you want to create an additional seed for a table that has an existing seed without overwriting the existing one.

Examples:

```
$ php artisan iseed my_table --classnameprefix=Customized
```

outputs `CustomizedMyTableSeeder.php`

```
$ php artisan iseed my_table,another_table --classnameprefix=Customized
```

outputs `CustomizedMyTableSeeder.php` and `CustomizedAnotherTableSeeder.php`

```
$ php artisan iseed my_table --classnamesuffix=Customizations
```

outputs `MyTableCustomizationsSeeder.php`

```
$ php artisan iseed my_table,another_table --classnamesuffix=Customizations
```

outputs `MyTableCustomizationsSeeder.php` and `AnotherTableCustomizationsSeeder.php`

### 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/seeders/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:

```
$ php artisan iseed users --max=10
```

### chunksize

[](#chunksize)

Optional parameter which defines the size of data chunks for each insert query.

Example:

```
$ php artisan iseed users --chunksize=100
```

Please note that some users encountered a problem with large DB table exports. The issue is solved by splitting input data into smaller chunks of elements per insert statement. You may need to change the chunk size value in some extreme cases where a DB table has a large number of records, the chunk size is configurable in Iseed's `config.php` file or via the `artisan` command.

### orderby

[](#orderby)

Optional parameter which defines the column which will be used to order the results by, when used in conjunction with the max parameter that allows you to set the desired number of exported database entries.

Example:

```
$ php artisan iseed users --max=10 --orderby=id
```

### direction

[](#direction)

Optional parameter which allows you to set the direction of the ordering of results; used in conjuction with orderby parameter.

Example:

```
$ php artisan iseed users --max=10 --orderby=id --direction=desc
```

### 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:

```
$ php artisan iseed users --exclude=id
$ php 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.

```
$ php 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.

```
$ php 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.

```
$ php 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.

```
$ php 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.

```
$ php 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.

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

### noindex

[](#noindex)

By using `--noindex` the seed can be generated as a non-indexed array. The use case for this feature is when you need to merge two seed files.

Example:

```
$ php artisan iseed users --noindex
```

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

[](#configuration)

Iseed comes with the following configuration, to change the default first publish the configuration with:

```
$ php artisan vendor:publish --provider="SchuBu\Iseed\IseedServiceProvider" --tag="config"
```

### path

[](#path)

Path where the seeders will be generated.

The default is `/database/seeders`.

### seeder\_path

[](#seeder_path)

Path where the Seeder file is saved.

The default is `/database/seeders/DatabaseSeeder.php`

### seeder\_modification

[](#seeder_modification)

Whether the Seeder should be modified after running the `iseed` command.

The default is `true`.

### chunk\_size

[](#chunk_size)

Maximum number of rows per insert statement.

The default is `500`.

### stub\_path

[](#stub_path)

You may alternatively set a relative path to a custom stub file. Make sure to make path relative to your project root, e.g. `'stub_path' => 'stubs/seeder.stub'` or `'stub_path' => './stubs/seeder.stub'` but **not** `'stub_path' => '/stubs/seeder.stub'`.

The default stub file is located in `/vendor/schubu/iseed/src/SchuBu/Iseed/Stubs/seed.stub`

### insert\_command

[](#insert_command)

You may customize the line that preceeds the inserts inside the seeder.

You **MUST** keep both `%s` however, the first will be replaced by the table name and the second by the inserts themselves.

The default is `\DB::table('%s')->insert(%s);`.

Usage
-----

[](#usage)

To generate a seed file for your individual tables simply call:

```
\Iseed::generateSeed($tableName);
```

`$tableName` needs to define the name of your table. There are also parameters you can pass to the `generateSeed()` method which include:

VariableDescriptionDefaultTypeRequired$tableNameTable namestring✅$prefixSeeder class prefixnullstring❌$suffixSeeder class suffixnullstring❌$databaseDatabase connection namenullstring❌$maxMaximum seeded entries0integer❌$chunkSizeSize of data chunks0integer❌$excludeColumns to excludenullstring❌$prerunEventPrerun event namenullstring❌$postrunEventPostrun event namenullstring❌$dumpAutoComposer auto-dumptruestring❌$indexedIndexed arraytruestring❌$orderByColumn to order bynullstring❌$directionDefault sort orderASCstring❌For example, to generate a seed for your `users` table you would call:

```
\Iseed::generateSeed('users', 'mysql2', 100);
```

This will create a file inside the `/database/seeders` folder (`/database/seeds` for Laravel 5 to 7 and `/app/database/seeds` for Laravel 4) called `UsersTableSeeder.php` with the contents similar to following example:

```
