88use Illuminate \Database \Eloquent \Model ;
99use Illuminate \Support \Arr ;
1010use Illuminate \Support \Facades \Cache ;
11- use Illuminate \Support \Facades \DB ;
12- use Illuminate \Support \Facades \Schema ;
1311
1412class ModelConfig
1513{
@@ -116,21 +114,22 @@ protected function getForbiddenColumns(array $forbiddenKeys): array
116114 public function getModelColumns (): array
117115 {
118116 $ table = $ this ->model ->getTable ();
117+ $ connection = $ this ->model ->getConnection ();
119118
120119 if (Cache::has (self ::CACHE_PREFIX . $ table )) {
121120 return Cache::get (self ::CACHE_PREFIX . $ table );
122121 }
123122
124- $ columns = Schema:: getColumnListing ($ table );
123+ $ columns = $ connection -> getSchemaBuilder ()-> getColumnListing ($ table );
125124 $ modelColumns = [];
126125
127- $ this ->registerEnumTypeForDoctrine ();
126+ $ this ->registerEnumTypeForDoctrine ($ connection );
128127
129128 try {
130129 foreach ($ columns as $ column ) {
131- $ modelColumns [$ column ] = DB :: getSchemaBuilder ()->getColumnType ($ table , $ column );
130+ $ modelColumns [$ column ] = $ connection -> getSchemaBuilder ()->getColumnType ($ table , $ column );
132131 }
133- } catch (Exception $ e ) {
132+ } catch (Exception ) {
134133 // leave model columns as an empty array and cache it.
135134 }
136135
@@ -143,10 +142,8 @@ public function getModelColumns(): array
143142 * Having 'enum' in table definition will throw Doctrine error because it is not defined in their types.
144143 * Registering it manually.
145144 */
146- protected function registerEnumTypeForDoctrine (): void
145+ protected function registerEnumTypeForDoctrine ($ connection ): void
147146 {
148- $ connection = DB ::connection ();
149-
150147 if (!class_exists ('Doctrine\DBAL\Driver\AbstractSQLiteDriver ' )) {
151148 return ;
152149 }
0 commit comments