Created
November 1, 2018 16:05
-
-
Save Vusys/7989d824c512516d6ea4dc18057f602b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
public function register() | |
{ | |
$this->app->singleton('command.migrate.fresh', function () { | |
return new FreshCommand(); | |
}); | |
} | |
//... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\Core\Console\Commands; | |
class FreshCommand extends \Illuminate\Database\Console\Migrations\FreshCommand | |
{ | |
/** | |
* Drop all of the database tables. | |
* | |
* @param string $database | |
* | |
* @return void | |
*/ | |
protected function dropAllTables($database): void | |
{ | |
/** @var \Illuminate\Database\DatabaseManager $db */ | |
$db = $this->laravel['db']; | |
$db->getSchemaBuilder()->disableForeignKeyConstraints(); | |
$this->info(PHP_EOL . hex2bin('28e295afc2b0e296a1c2b0efbc89e295afefb8b520e294bbe29481e294bb') . PHP_EOL); | |
foreach (['database-one', 'database-two', 'database-three'] as $dbName) { | |
$tables = $db->select("SHOW TABLES IN `{$dbName}`"); | |
$tables = array_column($tables, 'Tables_in_' . $dbName); | |
$tables = array_map(function ($table) use ($dbName) { | |
return '`' . $dbName . '`.`' . $table . '`'; | |
}, $tables); | |
foreach ($tables as $table) { | |
$db->statement("DROP TABLE {$table}"); | |
$this->info('Dropped ' . str_replace('`', '', $table)); | |
} | |
} | |
$db->getSchemaBuilder()->enableForeignKeyConstraints(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment