laravel-auto/migrations
Composer 安装命令:
composer require laravel-auto/migrations
包简介
Automatic Laravel model migrations.
README 文档
README
Instead 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.
This 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.
Documentation
Installation
Require the package via composer:
composer require laravel-auto/migrations
Usage
Declare a static migration method in your models:
namespace App\Models; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Eloquent\Model; class MyModel extends Model { public static function migration(Blueprint $table) { $table->id(); $table->string('name'); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); } }
Run the migrate:auto command:
php artisan migrate:auto
Commands
Making Models
Make a model with a migration method included:
php artisan make:amodel {class} {--force} {--f|no-factory} {--s|no-soft-delete} {--m|no-static-migration}
This command will also make a factory whose definition points to the model method. Use --force to overwrite an existing model.
Running Migrations
Run automatic migrations:
php artisan migrate:auto {--f|--fresh} {--s|--seed} {--force}
Use -f to wipe the database, -s to seed after migration, and --force to run migrations in production.
Migration Order
You 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.
class MyModel extends Model { public $migrationOrder = 1; public function migration(Blueprint $table) { $table->id(); $table->string('name'); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); } }
The 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 for this idea.
Publishing Stubs
Use your own model and factory stubs by publishing package files:
php artisan vendor:publish --tag=laravel-automatic-migrations
Update the stub_path in config/auto-migrate.php:
'stub_path' => resource_path('stubs/vendor/laravel-automatic-migrations'),
Now edit the stub files inside resources/stubs/vendor/laravel-automatic-migrations. Commands will now use these stub files to make models and factories.
laravel-auto/migrations 适用场景与选型建议
laravel-auto/migrations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.7k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 laravel-auto/migrations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-auto/migrations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-15