Skip to content

Commit 54c9649

Browse files
update on extractTableName()
1 parent 1f91e4c commit 54c9649

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Capsule/CommandHelper.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,30 @@ protected function hasOption(array $options, string $key): bool
9999
}
100100

101101
/**
102-
* Extract table name from a migration string like "create_users_table".
102+
* Extract table name from a migration string.
103+
* Supports common patterns like:
104+
* - create_users_table => users
105+
* - users_table => users
106+
* Fallback: returns a normalized name if no strict pattern matched.
103107
*
104108
* @param string|null $migration
105-
* @return string|null
109+
* @return string
106110
*/
107111
protected function extractTableName($migration = null)
108112
{
109-
// Ensure it matches the "create_*_table" pattern
110-
if (preg_match('/^create_(.+)_table$/', Str::lower($migration), $matches)) {
111-
return $matches[1]; // middle part (e.g., "users")
113+
$name = Str::lower($migration);
114+
115+
// 1) create_{table}_table
116+
if (preg_match('/^create_(.+)_table$/', $name, $matches)) {
117+
return $matches[1];
118+
}
119+
120+
// 2) anything ending with _table
121+
if (preg_match('/^(.+)_table$/', $name, $matches)) {
122+
return $matches[1];
112123
}
113124

114-
return null; // not a valid pattern
125+
return $migration;
115126
}
116127

117128
/**

0 commit comments

Comments
 (0)