@@ -31,19 +31,30 @@ public function down()
31
31
32
32
public function updateIndexNames ($ from , $ to , $ table )
33
33
{
34
- $ sm = Schema::getConnection ()->getDoctrineSchemaManager ();
34
+ Schema::table ($ table , function ($ blueprint ) use ($ from , $ to ) {
35
+ foreach ($ this ->getIndexes ($ blueprint ) as $ index ) {
36
+ if (is_object ($ index ) ? $ index ->isPrimary () : $ index ['primary ' ]) {
37
+ continue ;
38
+ }
35
39
36
- $ table = $ sm ->listTableDetails ($ table );
40
+ $ old = is_object ($ index ) ? $ index ->getName () : $ index ['name ' ];
41
+ $ new = str_replace ($ from , $ to , $ old );
37
42
38
- foreach ($ table ->getIndexes () as $ index ) {
39
- if ($ index ->isPrimary ()) {
40
- continue ;
43
+ $ blueprint ->renameIndex ($ old , $ new );
41
44
}
45
+ });
46
+ }
42
47
43
- $ old = $ index ->getName ();
44
- $ new = str_replace ($ from , $ to , $ old );
45
-
46
- $ table ->renameIndex ($ old , $ new );
48
+ public function getIndexes ($ blueprint )
49
+ {
50
+ $ connection = Schema::getConnection ();
51
+ $ table = $ blueprint ->getTable ();
52
+
53
+ if (method_exists ($ connection , 'getDoctrineSchemaManager ' )) {
54
+ $ sm = $ connection ->getDoctrineSchemaManager ();
55
+ return $ sm ->listTableDetails ($ table )->getIndexes ();
56
+ } else {
57
+ return $ connection ->getSchemaBuilder ()->getIndexes ($ table );
47
58
}
48
59
}
49
60
}
0 commit comments