Download the PHP package orangehill/iseed without Composer
On this page you can find all versions of the php package orangehill/iseed. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download orangehill/iseed
More information about orangehill/iseed
Files in orangehill/iseed
Package iseed
Short Description Generate a new Laravel database seed file based on data from the existing database table.
License BSD-2-Clause
Informations about the package iseed
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.
Installation
1. Require with Composer
Laravel 5.3.7 and below or Laravel 4 need specific version
2. Add Service Provider (Laravel 5.4 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
:
Artisan command options
[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:
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:
outputs CustomizedMyTableSeeder.php
outputs CustomizedMyTableSeeder.php and CustomizedAnotherTableSeeder.php
outputs MyTableCustomizationsSeeder.php
outputs MyTableCustomizationsSeeder.php and AnotherTableCustomizationsSeeder.php
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.
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:
clean
Optional parameter which will clean app/database/seeds/DatabaseSeeder.php
before creating new seed class.
Example:
database
Optional parameter which specifies the DB connection name.
Example:
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:
chunksize
Optional parameter which defines the size of data chunks for each insert query.
Example:
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:
direction
Optional parameter which allows you to set the direction of the ordering of results; used in conjuction with orderby parameter.
Example:
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:
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.
The following example will assign someUserEvent
to users
table seed, and someGroupEvent
to groups
table seed, to be executed before seeding.
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.
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.
The following example will assign someUserEvent
to users
table seed, and someGroupEvent
to groups
table seed, to be executed after seeding.
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.
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:
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:
This command will also update /database/seeds/DatabaseSeeder.php
(/app/database/seeds/DatabaseSeeder.php
for Laravel 4) to include a call to this newly generated seed class.
If you wish you can define custom iSeed template in which all the calls will be placed. You can do this by using #iseed_start
and #iseed_end
templates anywhere within /database/seeds/DatabaseSeeder.php
(/app/database/seeds/DatabaseSeeder.php
for Laravel 4), for example:
Alternatively you can run Iseed from the command line using Artisan, e.g. php artisan iseed users
. For generation of multiple seed files comma separated list of table names should be send as an argument for command, e.g. php artisan iseed users,posts,groups
.
In case you try to generate seed file that already exists command will ask you a question whether you want to overwrite it or not. If you wish to overwrite it by default use --force
Artisan Command Option, e.g. php artisan iseed users --force
.
If you wish to clear iSeed template you can use Artisan Command Option --clean
, e.g. php artisan iseed users --clean
. This will clean template from app/database/seeds/DatabaseSeeder.php
before creating new seed class.
You can specify db connection that will be used for creation of new seed files by using Artisan Command Option --database=connection_name
, e.g. php artisan iseed users --database=mysql2
.
To limit number of rows that will be exported from table use Artisan Command Option --max=number_of_rows
, e.g. php artisan iseed users --max=10
. If you use this option while exporting multiple tables specified limit will be applied to all of them.
To (re)seed the database go to the Terminal and run Laravel's db:seed command
(php artisan db:seed
).
Please note that some users encountered a problem with large DB table exports (error when seeding from table with many records). The issue was solved by splitting input data into smaller chunks of elements per insert statement. As you may need to change the chunk size value in some extreme cases where DB table has a large number of columns, the chunk size is configurable in iSeed's config.php
file:
'chunk_size' => 500 // Maximum number of rows per insert statement
All versions of iseed with dependencies
illuminate/support Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0