33namespace BeyondCode \ErdGenerator ;
44
55use Illuminate \Database \Eloquent \Relations \BelongsToMany ;
6+ use Illuminate \Support \Facades \Schema ;
67use phpDocumentor \GraphViz \Graph ;
78use Illuminate \Support \Collection ;
89use phpDocumentor \GraphViz \Node ;
@@ -111,6 +112,11 @@ protected function getTableColumnsFromModel(EloquentModel $model)
111112 } catch (\Throwable $ e ) {
112113 }
113114
115+ try {
116+ return Schema::getColumns ($ model ->getTable ());
117+ } catch (\Throwable $ e ) {
118+ }
119+
114120 return [];
115121 }
116122
@@ -123,11 +129,18 @@ protected function getModelLabel(EloquentModel $model, string $label)
123129 if (config ('erd-generator.use_db_schema ' )) {
124130 $ columns = $ this ->getTableColumnsFromModel ($ model );
125131 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 ;
127140 if (config ('erd-generator.use_column_types ' )) {
128- $ label .= ' ( ' .$ column -> getType ()-> getName () .') ' ;
141+ $ label .= ' ( ' . $ typeName .') ' ;
129142 }
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 ;
131144 }
132145 }
133146
0 commit comments