PHPackages                             masitings/seedmaker - 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. masitings/seedmaker

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

masitings/seedmaker
===================

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

1.0(3y ago)044BSD-2-ClausePHPPHP ^7.2|^8.0.2

Since Mar 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/masitings/seedmaker)[ Packagist](https://packagist.org/packages/masitings/seedmaker)[ RSS](/packages/masitings-seedmaker/feed)WikiDiscussions master Synced 1mo ago

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

is a Laravel package that provides a method to generate a new seed file based on data from the existing database table.

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

[](#installation)

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

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

```
composer require masitings/seedmaker
```

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 seedmaker my_table

```

```
php artisan seedmaker 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 seedmaker my_table --classnameprefix=Customized

```

outputs CustomizedMyTableSeeder.php

```
php artisan seedmaker my_table,another_table --classnameprefix=Customized

```

outputs CustomizedMyTableSeeder.php and CustomizedAnotherTableSeeder.php

```
php artisan seedmaker my_table --classnamesuffix=Customizations

```

outputs MyTableCustomizationsSeeder.php

```
php artisan seedmaker 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 seedmaker 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 seedmaker users --dumpauto=false

```

### clean

[](#clean)

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

Example:

```
php artisan seedmaker users --clean

```

### database

[](#database)

Optional parameter which specifies the DB connection name.

Example:

```
php artisan seedmaker 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 seedmaker users --max=10

```

### chunksize

[](#chunksize)

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

Example:

```
php artisan seedmaker users --chunksize=100

```

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

```
artisan seedmaker 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:

```
artisan seedmaker 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 seedmaker users --exclude=id
php artisan seedmaker 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 seedmaker 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 seedmaker 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 seedmaker 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 seedmaker 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 seedmaker 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 seedmaker 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 seedmaker users --noindex

```

Usage
-----

[](#usage)

To generate a seed file for your users table simply call: `\seedmaker::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:

```
