3
3
namespace BeyondCode \ErdGenerator ;
4
4
5
5
use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
6
+ use Illuminate \Support \Facades \Schema ;
6
7
use phpDocumentor \GraphViz \Graph ;
7
8
use Illuminate \Support \Collection ;
8
9
use phpDocumentor \GraphViz \Node ;
@@ -111,6 +112,11 @@ protected function getTableColumnsFromModel(EloquentModel $model)
111
112
} catch (\Throwable $ e ) {
112
113
}
113
114
115
+ try {
116
+ return Schema::getColumns ($ model ->getTable ());
117
+ } catch (\Throwable $ e ) {
118
+ }
119
+
114
120
return [];
115
121
}
116
122
@@ -123,11 +129,18 @@ protected function getModelLabel(EloquentModel $model, string $label)
123
129
if (config ('erd-generator.use_db_schema ' )) {
124
130
$ columns = $ this ->getTableColumnsFromModel ($ model );
125
131
foreach ($ columns as $ column ) {
126
- $ label = $ column ->getName ();
132
+ if (is_object ($ column )) {
133
+ $ name = $ column ->getName ();
134
+ $ typeName = $ column ->getType ()->getName ();
135
+ } else { // it's an array!
136
+ $ name = $ column ['name ' ] ?? '' ;
137
+ $ typeName = $ column ['type_name ' ] ?? '' ;
138
+ }
139
+ $ label = $ name ;
127
140
if (config ('erd-generator.use_column_types ' )) {
128
- $ label .= ' ( ' .$ column -> getType ()-> getName () .') ' ;
141
+ $ label .= ' ( ' . $ typeName .') ' ;
129
142
}
130
- $ table .= '<tr width="100%"><td port=" ' . $ column -> getName () . '" align="left" width="100%" bgcolor=" ' .config ('erd-generator.table.row_background_color ' ).'"><font color=" ' .config ('erd-generator.table.row_font_color ' ).'" > ' . $ label . '</font></td></tr> ' . PHP_EOL ;
143
+ $ table .= '<tr width="100%"><td port=" ' . $ name . '" align="left" width="100%" bgcolor=" ' .config ('erd-generator.table.row_background_color ' ).'"><font color=" ' .config ('erd-generator.table.row_font_color ' ).'" > ' . $ label . '</font></td></tr> ' . PHP_EOL ;
131
144
}
132
145
}
133
146
0 commit comments