Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MigrationCreatorPatch-Issue-24907] Reference a variable of the insta… #24908

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Illuminate/Database/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class MigrationCreator
*/
protected $postCreate = [];

/**
* The table.
*
* @var string
*/
protected $table;

/**
* Create a new migration creator instance.
*
Expand All @@ -48,6 +55,10 @@ public function create($name, $path, $table = null, $create = false)
{
$this->ensureMigrationDoesntAlreadyExist($name);

// We are assigning the variable to the instance for backwards compatibility with prior versions
// so that it can be used in the firePostCreateHooks
$this->table = $table;

// First we will get the stub file for the migration, which serves as a type
// of template for the migration. Once we have those we will populate the
// various place-holders, save the file, and run the post create event.
Expand All @@ -61,7 +72,7 @@ public function create($name, $path, $table = null, $create = false)
// Next, we will fire any hooks that are supposed to fire after a migration is
// created. Once that is done we'll be ready to return the full path to the
// migration file so it can be used however it's needed by the developer.
$this->firePostCreateHooks($table);
$this->firePostCreateHooks();

return $path;
}
Expand Down Expand Up @@ -150,13 +161,12 @@ protected function getPath($name, $path)
/**
* Fire the registered post create hooks.
*
* @param string $table
* @return void
*/
protected function firePostCreateHooks($table)
protected function firePostCreateHooks()
{
foreach ($this->postCreate as $callback) {
call_user_func($callback, $table);
call_user_func($callback, $this->table);
}
}

Expand Down