{"id":13396159,"url":"https://github.com/orangehill/iseed","last_synced_at":"2026-02-23T09:30:15.794Z","repository":{"id":37492924,"uuid":"11476171","full_name":"orangehill/iseed","owner":"orangehill","description":"Laravel Inverse Seed Generator","archived":false,"fork":false,"pushed_at":"2025-03-04T07:58:04.000Z","size":171,"stargazers_count":2855,"open_issues_count":90,"forks_count":394,"subscribers_count":53,"default_branch":"master","last_synced_at":"2025-05-07T20:29:00.482Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orangehill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-17T13:05:30.000Z","updated_at":"2025-05-06T04:29:31.000Z","dependencies_parsed_at":"2025-04-01T17:11:08.443Z","dependency_job_id":"9315f9a1-69ac-43d8-ba0c-6d967ae6de7b","html_url":"https://github.com/orangehill/iseed","commit_stats":{"total_commits":111,"total_committers":28,"mean_commits":"3.9642857142857144","dds":0.6126126126126126,"last_synced_commit":"92b98c8bda6280afa0fac016b1b49caf6f57f18d"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangehill%2Fiseed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangehill%2Fiseed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangehill%2Fiseed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orangehill%2Fiseed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orangehill","download_url":"https://codeload.github.com/orangehill/iseed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227603,"owners_count":22035667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:41.512Z","updated_at":"2026-02-23T09:30:15.722Z","avatar_url":"https://github.com/orangehill.png","language":"PHP","funding_links":[],"categories":["Popular Packages","Paquetes utiles","Packages","迁移( Migrations )"],"sub_categories":["Helpers/General"],"readme":"**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.\n\n[![Latest Stable Version](https://poser.pugx.org/orangehill/iseed/v/stable.svg)](https://packagist.org/packages/orangehill/iseed)\n[![Total Downloads](https://poser.pugx.org/orangehill/iseed/downloads.svg)](https://packagist.org/packages/orangehill/iseed)\n[![License](https://poser.pugx.org/orangehill/iseed/license.svg)](https://packagist.org/packages/orangehill/iseed)\n\n**Supports Laravel 8, 9, 10, 11, 12, and 13** (PHP 8.0+)\n\n## Installation\n\n### 1. Require with [Composer](https://getcomposer.org/)\n```sh\ncomposer require orangehill/iseed\n```\n\n**Laravel 5.3.7 and below** or **Laravel 4** need specific version\n\n```sh\ncomposer require orangehill/iseed:2.2 # Laravel 5.3.7 and below\ncomposer require orangehill/iseed:1.1 # Laravel 4\n```\n\n### 2. Add Service Provider (Laravel 5.4 and below)\n\nLatest Laravel versions have auto discovery 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`:\n\n```php\n// ...\nOrangehill\\Iseed\\IseedServiceProvider::class,\n```\n\n## Artisan command options\n\n### [table_name]\nOptional. This parameter defines which table(s) will be used for seed creation.\n\nIf provided:\nUse CSV notation to list one or more table names. A seed file will be generated for each specified table.\n\nExamples Generate a seed file for a single table:\n```\nphp artisan iseed my_table\n```\nExample Generate seed files for multiple tables:\n\n```\nphp artisan iseed my_table,another_table\n```\n\nIf omitted:\nThe command automatically retrieves all table names from your database and generates seeders for every table.\nExamples:\n```\nphp artisan iseed\n```\n\n### classnameprefix \u0026 classnamesuffix\nOptionally specify a prefix or suffix for the Seeder class name and file name.\nThis is useful if you want to create an additional seed for a table that has an existing seed without overwriting the existing one.\n\nExamples:\n\n```\nphp artisan iseed my_table --classnameprefix=Customized\n```\noutputs CustomizedMyTableSeeder.php\n\n```\nphp artisan iseed my_table,another_table --classnameprefix=Customized\n```\noutputs CustomizedMyTableSeeder.php and CustomizedAnotherTableSeeder.php\n\n```\nphp artisan iseed my_table --classnamesuffix=Customizations\n```\noutputs MyTableCustomizationsSeeder.php\n\n```\nphp artisan iseed my_table,another_table --classnamesuffix=Customizations\n```\noutputs MyTableCustomizationsSeeder.php and AnotherTableCustomizationsSeeder.php\n\n### force\nOptional parameter which is used to automatically overwrite any existing seeds for desired tables\n\nExample:\nThe following command will overwrite `UsersTableSeeder.php` if it already exists in laravel's seeds directory.\n```\nphp artisan iseed users --force\n```\n\n### dumpauto\nOptional boolean parameter that controls the execution of `composer dump-autoload` command. Defaults to true.\n\nExample that will stop `composer dump-autoload` from execution:\n```\nphp artisan iseed users --dumpauto=false\n```\n\n### clean\nOptional parameter which will clean `database/seeders/DatabaseSeeder.php` before creating new seed class.\n\nExample:\n```\nphp artisan iseed users --clean\n```\n\n### database\nOptional parameter which specifies the DB connection name. When using a non-default connection, the generated seeder will include the connection specification (e.g., `\\DB::connection('mysql2')-\u003etable(...)`) to ensure the seeder targets the correct database.\n\nExample:\n```\nphp artisan iseed users --database=mysql2\n```\n\n### max\nOptional 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.\n\nExample:\n```\nphp artisan iseed users --max=10\n```\n\n### chunksize\nOptional parameter which defines the size of data chunks for each insert query.\n\nExample:\n```\nphp artisan iseed users --chunksize=100\n```\n\n### orderby\nOptional 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.\n\nExample:\n```\nartisan iseed users --max=10 --orderby=id\n```\n\n### direction\nOptional parameter which allows you to set the direction of the ordering of results; used in conjunction with orderby parameter.\n\nExample:\n```\nartisan iseed users --max=10 --orderby=id --direction=desc\n```\n\n### exclude\nOptional 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.\n\nExample:\n```\nphp artisan iseed users --exclude=id\nphp artisan iseed users --exclude=id,created_at,updated_at\n```\n\n### prerun\nOptional parameter which assigns a laravel event name to be fired before seeding takes place. If an event listener returns `false`, seed will fail automatically.\nYou 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.\n\nExample:\nThe following command will make a seed file which will fire an event named 'someEvent' before seeding takes place.\n```\nphp artisan iseed users --prerun=someEvent\n```\nThe following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed before seeding.\n```\nphp artisan iseed users,groups --prerun=someUserEvent,someGroupEvent\n```\nThe 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.\n```\nphp artisan iseed users,groups --prerun=,someGroupEvent\n```\n\n### postrun\nOptional 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.\nYou 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.\n\nExample:\nThe following command will make a seed file which will fire an event named 'someEvent' after seeding was completed.\n```\nphp artisan iseed users --postrun=someEvent\n```\nThe following example will assign `someUserEvent` to `users` table seed, and `someGroupEvent` to `groups` table seed, to be executed after seeding.\n```\nphp artisan iseed users,groups --postrun=someUserEvent,someGroupEvent\n```\nThe 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.\n```\nphp artisan iseed users,groups --postrun=,someGroupEvent\n```\n\n### noindex\nBy using --noindex the seed can be generated as a non-indexed array.\nThe use case for this feature is when you need to merge two seed files.\n\nExample:\n```\nphp artisan iseed users --noindex\n```\n\n### noregister\nBy using --noregister the seed file will be generated but will not be added to `DatabaseSeeder.php`. This is useful when you want to create backup seeders or manually manage which seeders are registered.\n\nExample:\n```\nphp artisan iseed users --noregister\n```\n\n### skip-fk-checks\nBy using --skip-fk-checks the generated seeder will include statements to disable foreign key checks before deleting/inserting and re-enable them afterwards. This is useful when seeding tables that have foreign key constraints, as it prevents \"foreign key constraint failed\" errors.\n\nExample:\n```\nphp artisan iseed users --skip-fk-checks\n```\n\n**Note**: This option generates MySQL-specific `SET FOREIGN_KEY_CHECKS` statements.\n\n### reset-sequences\nBy using --reset-sequences the generated seeder will include statements to reset PostgreSQL sequences after seeding. This prevents \"duplicate key value violates unique constraint\" errors that can occur when inserting new records after seeding, because PostgreSQL sequences don't automatically reset when using DELETE.\n\nExample:\n```\nphp artisan iseed users --reset-sequences\n```\n\nThe generated seeder will include code to reset the sequence to the maximum ID value in the table:\n```php\nif (\\DB::getDriverName() === 'pgsql') {\n    \\DB::statement(\"SELECT setval(pg_get_serial_sequence('users', 'id'), COALESCE((SELECT MAX(id) FROM users), 1))\");\n}\n```\n\n**Note**: This option generates PostgreSQL-specific statements and only executes when the database driver is PostgreSQL.\n\n### skip\nOptional parameter which defines the number of rows to skip before exporting. This is useful for paginating through large tables in combination with the `--max` option.\n\nExample:\n```\nphp artisan iseed users --skip=1000\n```\n\nWhen combined with `--max` for pagination:\n```\nphp artisan iseed users --max=1000 --orderby=id\nphp artisan iseed users --max=1000 --skip=1000 --orderby=id\nphp artisan iseed users --max=1000 --skip=2000 --orderby=id\n```\n\n### where\nOptional parameter which allows you to specify a SQL WHERE clause to filter the rows that will be included in the seed file. The WHERE clause should be provided as a string and will be applied directly to the SQL query.\n\nExamples:\n```sh\n# Only seed users with example.com emails\nphp artisan iseed users --where=\"email LIKE '%@example.com'\"\n\n# Seed active users created after a specific date\nphp artisan iseed users --where=\"active = 1 AND created_at \u003e '2024-01-01'\"\n\n# Combine with other options\nphp artisan iseed users --where=\"role = 'admin'\" --max=10 --orderby=created_at --direction=desc\n```\n\n**Note**: When using complex WHERE clauses with special characters or spaces, make sure to properly escape and quote the condition string according to your shell's requirements.\n\n## Usage\n\nTo generate a seed file for your users table simply call: `\\Iseed::generateSeed('users', 'connectionName', 'numOfRows');`. `connectionName` and `numOfRows` are not required arguments.\n\nThis will create a file inside `/database/seeders`, with the contents similar to following example:\n\n```php\n\u003c?php\n\nnamespace Database\\Seeders;\n\n// File: /database/seeders/UsersTableSeeder.php\n\nuse Illuminate\\Database\\Seeder;\n\nclass UsersTableSeeder extends Seeder\n{\n\n    /**\n     * Auto generated seed file\n     *\n     * @return void\n     */\n    public function run()\n    {\n        \\DB::table('users')-\u003edelete();\n\n        \\DB::table('users')-\u003einsert(array (\n            0 =\u003e\n            array (\n                'id' =\u003e 1,\n                'email' =\u003e 'admin@admin.com',\n                'password' =\u003e '$2y$10$tUGCkQf/0NY3w1l9sobGsudt6UngnoVXx/lUoh9ElcSOD0ERRkK9C',\n                'name' =\u003e 'Admin User',\n                'created_at' =\u003e '2024-01-01 00:00:00',\n                'updated_at' =\u003e '2024-01-01 00:00:00',\n            ),\n            1 =\u003e\n            array (\n                'id' =\u003e 2,\n                'email' =\u003e 'user@user.com',\n                'password' =\u003e '$2y$10$ImNvsMzK/BOgNSYgpjs/3OjMKMHeA9BH/hjl43EiuBuLkZGPMuZ2W',\n                'name' =\u003e 'Regular User',\n                'created_at' =\u003e '2024-01-01 00:00:00',\n                'updated_at' =\u003e '2024-01-01 00:00:00',\n            ),\n        ));\n    }\n\n}\n```\n\nThis command will also update `/database/seeders/DatabaseSeeder.php` to include a call to this newly generated seed class.\n\nIf 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/seeders/DatabaseSeeder.php`, for example:\n\n```php\n\u003c?php\n\nnamespace Database\\Seeders;\n\n// File: /database/seeders/DatabaseSeeder.php\n\nuse Illuminate\\Database\\Seeder;\n\nclass DatabaseSeeder extends Seeder\n{\n\n    /**\n     * Run the database seeds.\n     *\n     * @return void\n        */\n    public function run()\n    {\n        #iseed_start\n\n        // All iSeed generated seeder calls will be placed here.\n\n        #iseed_end\n    }\n}\n```\n\nAlternatively 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`.\n\nIn 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`.\n\nIf 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 `database/seeders/DatabaseSeeder.php` before creating new seed class.\n\nYou 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`.\n\nTo 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.\n\nTo (re)seed the database go to the Terminal and run Laravel's `db:seed command` (`php artisan db:seed`).\n\nPlease note that some users encountered a problem with large DB table exports ([error when seeding from table with many records](https://github.com/orangehill/iseed/issues/4)). 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 rows, the chunk size is configurable in iSeed's `config.php` file:\n\n\t'chunk_size' =\u003e 500 // Maximum number of rows per insert statement\n\n## Custom Stub Template\n\nYou can customize the seed file template by creating a custom stub file and configuring iSeed to use it. Create a `config/iseed.php` file in your Laravel application:\n\n```php\n\u003c?php\nreturn [\n    'stub_path' =\u003e resource_path('stubs'),\n];\n```\n\nThen create your custom stub at `resources/stubs/seed.stub`. The stub supports the following placeholders:\n- `{{class}}` - The seeder class name\n- `{{table}}` - The database table name\n- `{{insert_statements}}` - The generated insert statements\n- `{{prerun_event}}` - Pre-run event code (if specified)\n- `{{postrun_event}}` - Post-run event code (if specified)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forangehill%2Fiseed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forangehill%2Fiseed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forangehill%2Fiseed/lists"}