diff --git a/app/Console/Commands/UpdateModelNamespaces.php b/app/Console/Commands/UpdateModelNamespaces.php new file mode 100755 index 00000000..b4f55b0e --- /dev/null +++ b/app/Console/Commands/UpdateModelNamespaces.php @@ -0,0 +1,56 @@ + ['uploadable_type'], + 'model_has_permissions' => ['model_type'], + 'model_has_roles' => ['model_type'], + 'media' => ['model_type'], + 'transfers' => ['transferable_type'], + ]; + + DB::beginTransaction(); + + try { + foreach ($tablesAndColumns as $table => $columns) { + foreach ($columns as $column) { + DB::table($table) + ->where($column, 'LIKE', "{$oldNamespace}%") + ->where($column, 'NOT LIKE', "{$newNamespace}%") // جلوگیری از اعمال تکراری + ->update([ + $column => DB::raw("REPLACE(`{$column}`, '{$oldNamespace}', '{$newNamespace}')") + ]); + } + } + + DB::commit(); + $this->info("Model namespaces updated successfully."); + + } catch (\Exception $e) { + DB::rollBack(); + $this->error("Error updating model namespaces: " . $e->getMessage()); + } + + return CommandAlias::SUCCESS; + } +}