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 ;
@@ -49,6 +50,11 @@ protected function getTableColumnsFromModel(EloquentModel $model)
49
50
} catch (\Throwable $ e ) {
50
51
}
51
52
53
+ try {
54
+ return Schema::getColumns ($ model ->getTable ());
55
+ } catch (\Throwable $ e ) {
56
+ }
57
+
52
58
return [];
53
59
}
54
60
@@ -61,11 +67,18 @@ protected function getModelLabel(EloquentModel $model, string $label)
61
67
if (config ('erd-generator.use_db_schema ' )) {
62
68
$ columns = $ this ->getTableColumnsFromModel ($ model );
63
69
foreach ($ columns as $ column ) {
64
- $ label = $ column ->getName ();
70
+ if (is_object ($ column )) {
71
+ $ name = $ column ->getName ();
72
+ $ typeName = $ column ->getType ()->getName ();
73
+ } else { // it's an array!
74
+ $ name = $ column ['name ' ];
75
+ $ typeName = $ column ['type_name ' ];
76
+ }
77
+ $ label = $ name ;
65
78
if (config ('erd-generator.use_column_types ' )) {
66
- $ label .= ' ( ' .$ column -> getType ()-> getName () .') ' ;
79
+ $ label .= ' ( ' . $ typeName .') ' ;
67
80
}
68
- $ 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 ;
81
+ $ 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 ;
69
82
}
70
83
}
71
84
0 commit comments