8
8
use Illuminate \Database \Eloquent \Model ;
9
9
use Illuminate \Support \Arr ;
10
10
use Illuminate \Support \Facades \Cache ;
11
- use Illuminate \Support \Facades \DB ;
12
- use Illuminate \Support \Facades \Schema ;
13
11
14
12
class ModelConfig
15
13
{
@@ -116,21 +114,22 @@ protected function getForbiddenColumns(array $forbiddenKeys): array
116
114
public function getModelColumns (): array
117
115
{
118
116
$ table = $ this ->model ->getTable ();
117
+ $ connection = $ this ->model ->getConnection ();
119
118
120
119
if (Cache::has (self ::CACHE_PREFIX . $ table )) {
121
120
return Cache::get (self ::CACHE_PREFIX . $ table );
122
121
}
123
122
124
- $ columns = Schema:: getColumnListing ($ table );
123
+ $ columns = $ connection -> getSchemaBuilder ()-> getColumnListing ($ table );
125
124
$ modelColumns = [];
126
125
127
- $ this ->registerEnumTypeForDoctrine ();
126
+ $ this ->registerEnumTypeForDoctrine ($ connection );
128
127
129
128
try {
130
129
foreach ($ columns as $ column ) {
131
- $ modelColumns [$ column ] = DB :: getSchemaBuilder ()->getColumnType ($ table , $ column );
130
+ $ modelColumns [$ column ] = $ connection -> getSchemaBuilder ()->getColumnType ($ table , $ column );
132
131
}
133
- } catch (Exception $ e ) {
132
+ } catch (Exception ) {
134
133
// leave model columns as an empty array and cache it.
135
134
}
136
135
@@ -143,10 +142,8 @@ public function getModelColumns(): array
143
142
* Having 'enum' in table definition will throw Doctrine error because it is not defined in their types.
144
143
* Registering it manually.
145
144
*/
146
- protected function registerEnumTypeForDoctrine (): void
145
+ protected function registerEnumTypeForDoctrine ($ connection ): void
147
146
{
148
- $ connection = DB ::connection ();
149
-
150
147
if (!class_exists ('Doctrine\DBAL\Driver\AbstractSQLiteDriver ' )) {
151
148
return ;
152
149
}
0 commit comments