class MigrationCreator

Constants

protected CURRENT_MIGRATION_PATH_CONTEXT_KEY_PREFIX

Properties

protected array<Closure(?string, string): void> $postCreate

The registered post create hooks.

Methods

__construct(Filesystem $files, string|null $customStubPath = null)

Create a new migration creator instance.

string
create(string $name, string $path, string|null $table = null, bool $create = false, string|null $stubPath = null)

Create a new migration at the given path.

void
ensureMigrationDoesntAlreadyExist(string $name, string|null $migrationPath = null)

Ensure that a migration with the given name doesn't already exist.

string
getStub(string|null $table, bool $create)

Get the migration stub file.

string
populateStub(string $stub, string|null $table)

Populate the place-holders in the migration stub.

string
getClassName(string $name)

Get the class name of a migration name.

string
getPath(string $name, string $path)

Get the full path to the migration.

string
getCollisionFreePath(string $name, string $path)

Get a collision-free full path to the migration.

void
firePostCreateHooks(string|null $table, string $path)

Fire the registered post create hooks.

void
afterCreate(Closure $callback)

Register a post migration create hook.

string
getDatePrefix()

Get the date prefix for the migration.

array
matchingFiles(string $pattern)

Get files matching the given pattern.

string
stubPath()

Get the path to the stubs.

getFilesystem()

Get the filesystem instance.

Details

at line 30
__construct(Filesystem $files, string|null $customStubPath = null)

Create a new migration creator instance.

Parameters

Filesystem $files
string|null $customStubPath

at line 41
string create(string $name, string $path, string|null $table = null, bool $create = false, string|null $stubPath = null)

Create a new migration at the given path.

Parameters

string $name
string $path
string|null $table
bool $create
string|null $stubPath

Return Value

string

Exceptions

Exception

at line 74
protected void ensureMigrationDoesntAlreadyExist(string $name, string|null $migrationPath = null)

Ensure that a migration with the given name doesn't already exist.

Parameters

string $name
string|null $migrationPath

Return Value

void

Exceptions

InvalidArgumentException

at line 92
protected string getStub(string|null $table, bool $create)

Get the migration stub file.

Parameters

string|null $table
bool $create

Return Value

string

at line 114
protected string populateStub(string $stub, string|null $table)

Populate the place-holders in the migration stub.

Parameters

string $stub
string|null $table

Return Value

string

at line 133
protected string getClassName(string $name)

Get the class name of a migration name.

Parameters

string $name

Return Value

string

at line 141
protected string getPath(string $name, string $path)

Get the full path to the migration.

Parameters

string $name
string $path

Return Value

string

at line 149
protected string getCollisionFreePath(string $name, string $path)

Get a collision-free full path to the migration.

Parameters

string $name
string $path

Return Value

string

at line 165
protected void firePostCreateHooks(string|null $table, string $path)

Fire the registered post create hooks.

Parameters

string|null $table
string $path

Return Value

void

at line 180
void afterCreate(Closure $callback)

Register a post migration create hook.

Boot-only. Hooks persist on the migration creator for the worker lifetime and run for every subsequent migration creation.

Parameters

Closure $callback

Return Value

void

at line 188
protected string getDatePrefix()

Get the date prefix for the migration.

Return Value

string

at line 212
protected array matchingFiles(string $pattern)

Get files matching the given pattern.

Parameters

string $pattern

Return Value

array

at line 226
string stubPath()

Get the path to the stubs.

Return Value

string

at line 234
Filesystem getFilesystem()

Get the filesystem instance.

Return Value

Filesystem