@@ -20,27 +20,45 @@ public function getData()
20
20
21
21
$ this ->collections = [];
22
22
foreach ($ tables as $ table ) {
23
- $ columns = $ schema ->listTableColumns ($ table );
24
- $ foreignKeys = collect ($ schema ->listTableForeignKeys ($ table ))->keyBy (function ($ foreignColumn ) {
25
- return $ foreignColumn ->getLocalColumns ()[0 ];
23
+ $ columns = method_exists ($ schema , 'listTableColumns ' )
24
+ ? $ schema ->listTableColumns ($ table )
25
+ : $ schema ->getColumns ($ table );
26
+ $ foreignKeys = collect (
27
+ method_exists ($ schema , 'listTableForeignKeys ' )
28
+ ? $ schema ->listTableForeignKeys ($ table )
29
+ : $ schema ->getForeignKeys ($ table )
30
+ )->keyBy (function ($ foreignColumn ) {
31
+ if (is_object ($ foreignColumn ) && method_exists ($ foreignColumn , 'getLocalColumns ' )) {
32
+ return $ foreignColumn ->getLocalColumns ()[0 ];
33
+ }
34
+
35
+ return data_get ($ foreignColumn , 'columns.0 ' );
26
36
});
27
37
28
38
foreach ($ columns as $ column ) {
29
- $ columnName = $ column ->getName ();
30
- $ columnType = $ column ->getType ()->getName ();
39
+ $ columnName = is_object ( $ column) && method_exists ( $ column , ' getName ' ) ? $ column ->getName () : data_get ( $ column , ' name ' );
40
+ $ columnType = is_object ( $ column) && method_exists ( $ column , ' getType ' ) ? $ column ->getType ()->getName () : data_get ( $ column , ' type_name ' );
31
41
if (isset ($ foreignKeys [$ columnName ])) {
32
42
$ foreignColumn = $ foreignKeys [$ columnName ];
33
- $ foreignTable = $ foreignColumn ->getForeignTableName ();
43
+ $ foreignTable = is_object ($ foreignColumn ) && method_exists ($ foreignColumn , 'getForeignTableName ' )
44
+ ? $ foreignColumn ->getForeignTableName ()
45
+ : data_get ($ foreignColumn , 'foreign_table ' );
34
46
$ columnType = 'FK -> ' .$ foreignTable ;
35
47
}
36
- $ length = $ column ->getLength ();
48
+ $ length = is_object ( $ column) && method_exists ( $ column , ' getLength ' ) ? $ column ->getLength () : count ( $ columns );
37
49
38
50
$ details ['column ' ] = $ columnName ;
39
51
$ details ['type ' ] = $ columnType .$ this ->determineUnsigned ($ column );
40
52
$ details ['length ' ] = $ length != 0 ? $ length : null ;
41
53
$ details ['default ' ] = $ this ->getDefaultValue ($ column );
42
- $ details ['nullable ' ] = $ this ->getExpression (! $ column ->getNotNull () === true );
43
- $ details ['comment ' ] = $ column ->getComment ();
54
+ $ details ['nullable ' ] = $ this ->getExpression (
55
+ is_object ($ column ) && method_exists ($ column , 'getNotNull ' )
56
+ ? ! $ column ->getNotNull () === true
57
+ : ! data_get ($ column , 'nullable ' )
58
+ );
59
+ $ details ['comment ' ] = is_object ($ column ) && method_exists ($ column , 'getComment ' )
60
+ ? $ column ->getComment ()
61
+ : data_get ($ column , 'comment ' );
44
62
45
63
$ this ->collections [$ table ][] = $ details ;
46
64
}
@@ -51,16 +69,26 @@ public function getData()
51
69
52
70
private function determineUnsigned ($ column )
53
71
{
54
- return ($ column ->getUnsigned () === true ) ? '(unsigned) ' : '' ;
72
+ if (is_object ($ column ) && method_exists ($ column , 'getUnsigned ' )) {
73
+ return ($ column ->getUnsigned () === true ) ? '(unsigned) ' : '' ;
74
+ }
75
+
76
+ return str_contains (
77
+ data_get ($ column , 'type ' ), 'unsigned '
78
+ ) === true ? '(unsigned) ' : '' ;
55
79
}
56
80
57
81
private function getDefaultValue ($ column )
58
82
{
59
- if ($ column ->getType ()->getName () == 'boolean ' ) {
83
+ if (is_object ( $ column ) && method_exists ( $ column , ' getType ' ) && $ column ->getType ()->getName () == 'boolean ' ) {
60
84
return $ column ->getDefault () ? 'true ' : 'false ' ;
61
85
}
62
86
63
- return $ column ->getDefault ();
87
+ if (is_object ($ column ) && method_exists ($ column , 'getDefault ' )) {
88
+ return $ column ->getDefault ();
89
+ }
90
+
91
+ return data_get ($ column , 'default ' ) ? 'true ' : 'false ' ;
64
92
}
65
93
66
94
private function getExpression ($ status )
0 commit comments