可以修改由 artisan migrate 命令创建的模板吗?
我为我的迁移创建了一个基类.目前我运行 artisan migrate 命令,它创建了一个扩展 Migrations 文件的新迁移,但是我想包含我的 BaseMigration 并从那里扩展它.我一直在手动进行此更改,但我觉得我在不必要地重复自己.
I've created a base class for my migrations. At the moment I run the artisan migrate command and it creates a new migration that extends the Migrations file, however I want to include my BaseMigration and extend it from there. I've been making this changes manualy but I feel like I'm repeating myself unnecessarily.
关于如何让新迁移自动扩展和加载我的基础迁移有什么建议吗?
Any advice on how to have new migrations automatically extend and load my base migration?
推荐答案
我不认为你可以,因为 Laravel 从 vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs
文件夹,你不能改变它,但你有一些选择:
I don't think you can, because Laravel takes migrations from the vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs
folder and you cannot change that, but you have some options:
1) 创建您自己的工匠命令migrate:makemyown
.
1) Create your own artisan command migrate:makemyown
.
2) 使用 Jeffrey Way 的 Laravel 生成器.他们让您通过以下方式创建迁移:
2) Use Jeffrey Way's Laravel Generators. They let you create your migrations by doing:
php artisan generate:migration create_posts_table --fields="title:string, description:text"
如果您只有一些需要开始的字段,而不是更具体的字段,那么它真的很好.
If you just have some fields you need to start with and not something more specific than that, it works really fine.
3) 编辑 Laravel 存根,但问题是一旦你 composer update
它们可能会被 Composer 覆盖.
3) Edit Laravel stubs, but the problem is that as soon as you composer update
they might get overwritten by Composer.
相关文章