{"id":21542632,"url":"https://github.com/bastinald/laravel-automatic-migrations","last_synced_at":"2025-04-10T04:25:17.060Z","repository":{"id":42975284,"uuid":"361619956","full_name":"bastinald/laravel-automatic-migrations","owner":"bastinald","description":"Automatic Laravel model migrations.","archived":false,"fork":false,"pushed_at":"2022-03-25T11:22:46.000Z","size":61,"stargazers_count":45,"open_issues_count":9,"forks_count":11,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T05:43:45.357Z","etag":null,"topics":["database","eloquent","laravel","laravel-models","migrations","model","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bastinald.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-26T04:44:46.000Z","updated_at":"2025-03-06T21:40:04.000Z","dependencies_parsed_at":"2022-09-22T13:01:38.543Z","dependency_job_id":null,"html_url":"https://github.com/bastinald/laravel-automatic-migrations","commit_stats":null,"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-automatic-migrations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-automatic-migrations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-automatic-migrations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bastinald%2Flaravel-automatic-migrations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bastinald","download_url":"https://codeload.github.com/bastinald/laravel-automatic-migrations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247704579,"owners_count":20982299,"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":["database","eloquent","laravel","laravel-models","migrations","model","php"],"created_at":"2024-11-24T05:10:14.818Z","updated_at":"2025-04-10T04:25:17.044Z","avatar_url":"https://github.com/bastinald.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Automatic Migrations\n\nInstead of having to create and manage migration files, this package allows you to specify your migrations inside your model classes via a `migration` method. When you run the `migrate:auto` command, it uses Doctrine to compare your model `migration` methods to the existing schema, and applies the changes automatically.\n\nThis package works fine alongside traditional Laravel migration files, for the cases where you still need migrations that are not coupled to a model. When you run the `migrate:auto` command, it will run your traditional migrations first, and the automatic migrations afterwards.\n\n## Documentation\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Commands](#commands)\n    - [Making Models](#making-models)\n    - [Running Migrations](#running-migrations)\n- [Migration Order](#migration-order)\n- [Publishing Stubs](#publishing-stubs)\n\n## Installation\n\nRequire the package via composer:\n\n```console\ncomposer require bastinald/laravel-automatic-migrations\n```\n\n## Usage\n\nDeclare a `migration` method in your models:\n\n ```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass MyModel extends Model\n{\n    public function migration(Blueprint $table)\n    {\n        $table-\u003eid();\n        $table-\u003estring('name');\n        $table-\u003etimestamp('created_at')-\u003enullable();\n        $table-\u003etimestamp('updated_at')-\u003enullable();\n    }\n}\n ```\n\nRun the `migrate:auto` command:\n\n```console\nphp artisan migrate:auto\n```\n\n## Commands\n\n### Making Models\n\nMake a model with a `migration` method included:\n\n```console\nphp artisan make:amodel {class} {--force}\n```\n\nThis command will also make a factory whose `definition` points to the model method. Use `--force` to overwrite an existing model.\n\n### Running Migrations\n\nRun automatic migrations:\n\n```console\nphp artisan migrate:auto {--f|--fresh} {--s|--seed} {--force}\n```\n\nUse `-f` to wipe the database, `-s` to seed after migration, and `--force` to run migrations in production.\n\n## Migration Order\n\nYou can specify the order to run your model migrations by adding a public `migrationOrder` property to your models. This is useful for pivot tables or situations where you must create a certain table before another.\n\n```php\nclass MyModel extends Model\n{\n    public $migrationOrder = 1;\n\n    public function migration(Blueprint $table)\n    {\n        $table-\u003eid();\n        $table-\u003estring('name');\n        $table-\u003etimestamp('created_at')-\u003enullable();\n        $table-\u003etimestamp('updated_at')-\u003enullable();\n    }\n}\n```\n\nThe `migrate:auto` command will run the automatic migrations in the order specified. If no order is declared for a model, it will default to `0`. Thanks to [@vincentkedison](https://github.com/vincentkedison) for this idea.\n\n## Publishing Stubs\n\nUse your own model and factory stubs by publishing package files:\n\n```console\nphp artisan vendor:publish --tag=laravel-automatic-migrations\n```\n\nUpdate the `stub_path` in `config/laravel-automatic-migrations.php`:\n\n```php\n'stub_path' =\u003e resource_path('stubs/vendor/laravel-automatic-migrations'),\n```\n\nNow edit the stub files inside `resources/stubs/vendor/laravel-automatic-migrations`. Commands will now use these stub files to make models and factories.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbastinald%2Flaravel-automatic-migrations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbastinald%2Flaravel-automatic-migrations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbastinald%2Flaravel-automatic-migrations/lists"}