Tob*_*bia 10
这是可行的,至少在Laravel 5中是合乎逻辑的
子类MigrationCreator和覆盖getStubPath(),只是从原始类复制函数(它将使用您的子类__DIR__)
<?php
namespace App\Database;
use Illuminate\Database\Migrations\MigrationCreator;
class AppMigrationCreator extends MigrationCreator
{
public function getStubPath()
{
return __DIR__.'/stubs';
}
}
Run Code Online (Sandbox Code Playgroud)
编写服务提供程序以覆盖migration.creator您自己的子类(它必须是延迟服务提供程序,因为您不能使用急切的绑定覆盖延迟绑定):
<?php
namespace App\Database;
use Illuminate\Support\ServiceProvider;
class AppMigrationServiceProvider extends ServiceProvider
{
protected $defer = true;
public function register()
{
$this->app->singleton('migration.creator', function ($app) {
return new AppMigrationCreator($app['files']);
});
}
public function provides()
{
return ['migration.creator'];
}
}
Run Code Online (Sandbox Code Playgroud)
将服务提供商添加到默认服务提供商config/app.php 之后.
最后,vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs与您的MigrationCreator子类一起复制(在此示例中,它将成为app/Database/stubs)并根据您的需要编辑模板.
保留DummyClass和DummyTable替换名称,str_replace()以创建实际的迁移文件.
我不认为你可以,因为Laravel从vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs文件夹中进行迁移,你不能改变它,但你有一些选择:
1)创建自己的工匠命令migrate:makemyown.
2)使用Jeffrey Way的Laravel 4发电机.它们允许您通过执行以下操作来创建迁移:
php artisan generate:migration create_posts_table --fields="title:string, description:text"
Run Code Online (Sandbox Code Playgroud)
如果你只需要一些字段,而不是那些比这更具体的字段,它就可以正常工作.
3)编辑Laravel存根,但问题是,一旦你composer update被Composer覆盖,它们就会被覆盖.
| 归档时间: |
|
| 查看次数: |
4116 次 |
| 最近记录: |