It's doable in a fairly logical way, at least in Laravel 5
Subclass MigrationCreator
and override getStubPath()
, just copying the function over from the original class (it will use your subclass's __DIR__
)
<?php
namespace AppDatabase;
use IlluminateDatabaseMigrationsMigrationCreator;
class AppMigrationCreator extends MigrationCreator
{
public function getStubPath()
{
return __DIR__.'/stubs';
}
}
Write a service provider to override migration.creator
with your own subclass (it must be a deferred service provider, because you cannot override a deferred binding with an eager one):
<?php
namespace AppDatabase;
use IlluminateSupportServiceProvider;
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'];
}
}
Add your service provider to config/app.php
after the default ones.
Finally, copy vendor/laravel/framework/src/Illuminate/Database/Migrations/stubs
alongside your MigrationCreator subclass (in this example it would become app/Database/stubs
) and edit the templates to your needs.
Keep the DummyClass
and DummyTable
names, as they are replaced with str_replace()
to create the actual migrations files.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…