private function revertMigrations($module)
{
$migrations = json_decode($module->migrations);
$module_tables = explode('|', $module->table);
if (is_array($migrations)) {
// to run the migration in descending order
rsort($migrations);
// Delete all migration entries for the module
foreach ($migrations as $migration_file) {
if ($module->vendor) {
$migration_filename = app_path("Modules/{$module->vendor}/{$module->alias}/Database/Migrations/{$migration_file}.php");
} else {
$migration_filename = app_path("Modules/{$module->alias}/Database/Migrations/{$migration_file}.php");
}
require_once $migration_filename;
$file = implode('_', array_slice(explode('_', $migration_file), 4));
$class_name = studly_case($file);
$class = new $class_name();
// Run the down method in the migration file
$class->down();
DB::table('migrations')->where('migration', $migration_file)->delete();
}
}
// Drop all tables created by the module
foreach ($module_tables as $module_table) {
$vendor = Str::lower($module->vendor);
$sql = "DROP TABLE IF EXISTS mdl_{$vendor}_{$module_table}";
DB::statement($sql);
}
}