{"id":28560119,"url":"https://github.com/capsulescodes/laravel-population","last_synced_at":"2025-06-10T09:07:35.320Z","repository":{"id":213273210,"uuid":"700816836","full_name":"capsulescodes/laravel-population","owner":"capsulescodes","description":"Laravel command to manage your database in real time","archived":false,"fork":false,"pushed_at":"2025-06-01T22:28:08.000Z","size":178,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-02T08:34:30.105Z","etag":null,"topics":["laravel","migration","population"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/capsulescodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2023-10-05T10:59:35.000Z","updated_at":"2025-06-01T22:27:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"651f9f4d-9a65-494a-81e8-1537ac6ed98c","html_url":"https://github.com/capsulescodes/laravel-population","commit_stats":null,"previous_names":["capsulescodes/laravel-population"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capsulescodes%2Flaravel-population","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capsulescodes%2Flaravel-population/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capsulescodes%2Flaravel-population/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capsulescodes%2Flaravel-population/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/capsulescodes","download_url":"https://codeload.github.com/capsulescodes/laravel-population/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/capsulescodes%2Flaravel-population/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259043770,"owners_count":22797163,"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":["laravel","migration","population"],"created_at":"2025-06-10T09:07:33.974Z","updated_at":"2025-06-10T09:07:35.303Z","avatar_url":"https://github.com/capsulescodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\u003cimg src=\"art/capsules-laravel-population-image.png\" width=\"400px\" height=\"265px\" alt=\"Laravel Population\" /\u003e\u003c/p\u003e\n\nSimplify database migrations and ensure consistency with your database tables effortlessly.\n\nLaravel Population package provides a set of commands that parses your migrations and detects any disparities between them and your database tables. If differences are found, a wizard is triggered to help you migrate and seed the new tables with converted records.\n\n\u003cbr\u003e\n\nTypically, your `users` table might have a `name` column, but you need two separate columns : `first_name` and `last_name`. However, your database is already full of records.\n\n\u003cbr\u003e\n\n [This article](https://capsules.codes/en/blog/fyi/en-fyi-modify-tables-and-records-with-laravel-population) provides an in-depth exploration of the package.\n\n\u003cbr\u003e\n\n\u003e [!WARNING]\n\u003e We recommend exercising caution when using this package on production.\n\n\u003cbr\u003e\n\n## Installation\n\n```bash\ncomposer require --dev capsulescodes/laravel-population\n```\n\n\u003cbr\u003e\n\n## Usage\n\n\u003cbr\u003e\n\nLet's say, your current `users` table have a `name` column, but you need two separate columns : `first_name` and `last_name`. First, modify your migration :\n\n\u003cbr\u003e\n\n```diff\n...\nSchema::create( 'users', function( Blueprint $table )\n{\n    $table-\u003eid();\n-    $table-\u003estring( 'name' );\n+    $table-\u003estring( 'first_name' );\n+    $table-\u003estring( 'last_name' );\n} );\n...\n```\n\n\u003cbr\u003e\n\nNow unleash the magic :\n\n```bash\nphp artisan populate\n```\n\n\u003cbr\u003e\n\nThe populate command will display the changes made in the migration files and ask for confirmation.\n\n```bash\n   INFO  Migration changes :\n\n  create_users_table .......................................................................................................................... DONE\n\n   INFO  Table 'users' has changes.\n\n  ⇂ delete column : 'name' =\u003e type : varchar\n  ⇂ create column : 'first_name' =\u003e type : varchar\n  ⇂ create column : 'last_name' =\u003e type : varchar\n\n ┌ Do you want to proceed on populating the 'users' table? ─────┐\n │ Yes                                                          │\n └──────────────────────────────────────────────────────────────┘\n\n ┌ How would you like to convert the records for the column 'first_name' of type 'varchar'?  'fn( $attribute, $model ) =\u003e $attribute' ┐\n │ fn( $a, $b ) =\u003e explode( ' ', $b-\u003ename )[ 0 ]                                                                                      │\n └────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n\n ┌ How would you like to convert the records for the column 'last_name' of type 'varchar'?  'fn( $attribute, $model ) =\u003e $attribute' ┐\n │ fn( $a, $b ) =\u003e explode( ' ', $b-\u003ename )[ 1 ]                                                                                     │\n └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘\n\n   INFO  Population succeeded.\n   ```\n\nYour `users` table has been updated and seeded with converted records. Simple.\n\n\u003cbr\u003e\n\n```diff\nApp\\Models\\User\n{\n    id: 1,\n-    name: \"Louie Wolff\",\n+    first_name: \"Louie\",\n+    last_name: \"Wolff\",\n},\nApp\\Models\\User\n{\n    id: 2,\n-    name: \"Holly Waters\",\n+    first_name: \"Holly\",\n+    last_name: \"Waters\",\n},\nApp\\Models\\User\n{\n    id: 3,\n-    name: \"Colton Mueller\",\n+    first_name: \"Colton\",\n+    last_name: \"Mueller\",\n},\n...\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n```bash\n# The populator will ask you the formula to convert existing records\n'fn( $attribute, $model ) =\u003e $attribute'\n\n# The inital representation of the parameters\n$attribute = 'name'\n$model = '$user'\n\n# But you can decide to use any Laravel helpers instead\n'fn() =\u003e fake()-\u003efirstName()'\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\nIf you want to rollback the latest population :\n\n```bash\nphp artisan populate:rollback\n```\n\n\u003cbr\u003e\n\n```bash\n   WARN  The rollback command will only set back the latest copy of your database(s). You'll have to modify your migrations and models manually.\n\n   INFO  Database dump successfully reloaded.\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## Options\n\n\n```bash\nphp artisan populate --path={path-to-migrations-to-populate} --realpath={true|false} --database={database-name} --daptabase={database-name}\n```\n\n\u003cbr\u003e\n\n- Laravel Population supports SQLite, MySQL, MariaDB and PostgreSQL.\n- Laravel Population can work with multiple databases.\n- Laravel Population supports both anonymous and named migrations classes.\n- Laravel Population supports multiple table creation in migration files.\n\n\u003cbr\u003e\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\nIn order to run MySQL tests, credentials have to be configured in the intended TestCases.\n\n## Credits\n\n[Capsules Codes](https://github.com/capsulescodes)\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapsulescodes%2Flaravel-population","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcapsulescodes%2Flaravel-population","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcapsulescodes%2Flaravel-population/lists"}