Skip to content

Instantly share code, notes, and snippets.

@Vusys
Created November 1, 2018 16:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vusys/7989d824c512516d6ea4dc18057f602b to your computer and use it in GitHub Desktop.
Save Vusys/7989d824c512516d6ea4dc18057f602b to your computer and use it in GitHub Desktop.
//...
public function register()
{
$this->app->singleton('command.migrate.fresh', function () {
return new FreshCommand();
});
}
//...
<?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