@@ -15,34 +15,65 @@ public function getContents()
15
15
{
16
16
$ contents = $ this ->contents ;
17
17
$ output = [];
18
- foreach ($ contents as $ table => $ properties ) {
18
+
19
+ foreach ($ contents as $ table => $ rows ) {
20
+ // Normalize & de-duplicate rows for this table
21
+ // Supports both list-style rows and associative rows.
22
+ $ order = ['column ' , 'type ' , 'length ' , 'default ' , 'nullable ' , 'comment ' ];
23
+
24
+ $ unique = [];
25
+ foreach ($ rows as $ row ) {
26
+ if (is_array ($ row ) && array_is_list ($ row )) {
27
+ // Already positional
28
+ $ cells = array_map (fn ($ v ) => trim ((string ) $ v ), $ row );
29
+ } else {
30
+ // Map associative row to the expected column order
31
+ $ cells = [];
32
+ foreach ($ order as $ k ) {
33
+ $ cells [] = isset ($ row [$ k ]) ? trim ((string ) $ row [$ k ]) : '' ;
34
+ }
35
+ }
36
+
37
+ // Key for dedupe (stable & whitespace-normalized)
38
+ $ key = implode ('|| ' , $ cells );
39
+ if (! isset ($ unique [$ key ])) {
40
+ $ unique [$ key ] = $ cells ;
41
+ }
42
+ }
43
+
44
+ // Render table
19
45
$ output [] = '### ' .$ table .PHP_EOL .PHP_EOL ;
20
46
$ output [] = '| Column | Type | Length | Default | Nullable | Comment | ' .PHP_EOL ;
21
47
$ output [] = '|--------|------|--------|---------|----------|---------| ' .PHP_EOL ;
22
- foreach ($ properties as $ key => $ value ) {
23
- $ fields = [];
24
- foreach ($ value as $ k => $ v ) {
25
- $ fields [] = "{$ v }" ;
26
- }
27
- $ output [] = '| ' .implode (' | ' , $ fields ).' | ' .PHP_EOL ;
48
+
49
+ foreach ($ unique as $ cells ) {
50
+ // Ensure exactly 6 cells
51
+ $ cells = array_pad ($ cells , 6 , '' );
52
+ $ output [] = '| ' .implode (' | ' , $ cells ).' | ' .PHP_EOL ;
28
53
}
54
+
29
55
$ output [] = PHP_EOL ;
30
56
}
31
57
32
58
$ schema = implode ('' , $ output );
33
59
$ stub = $ this ->getStub ();
60
+
34
61
$ database_config = config ('database.connections. ' .$ this ->connection );
35
- $ host = isset ($ database_config ['host ' ]) ? $ database_config ['host ' ] : null ;
36
- $ port = isset ($ database_config ['port ' ]) ? $ database_config ['port ' ] : null ;
37
-
38
- return str_replace ([
39
- 'APP_NAME ' ,
40
- 'DB_CONNECTION ' , 'DB_HOST ' , 'DB_PORT ' , 'DB_DATABASE ' ,
41
- 'SCHEMA_CONTENT ' ,
42
- ], [
43
- config ('app.name ' ),
44
- $ this ->connection , $ host , $ port , $ database_config ['database ' ],
45
- $ schema ,
46
- ], $ stub );
62
+ $ host = $ database_config ['host ' ] ?? null ;
63
+ $ port = $ database_config ['port ' ] ?? null ;
64
+
65
+ return str_replace (
66
+ [
67
+ 'APP_NAME ' ,
68
+ 'DB_CONNECTION ' , 'DB_HOST ' , 'DB_PORT ' , 'DB_DATABASE ' ,
69
+ 'SCHEMA_CONTENT ' ,
70
+ ],
71
+ [
72
+ config ('app.name ' ),
73
+ $ this ->connection , $ host , $ port , $ database_config ['database ' ],
74
+ $ schema ,
75
+ ],
76
+ $ stub
77
+ );
47
78
}
48
79
}
0 commit comments