Skip to content

Commit f329faa

Browse files
NorgulStyleCIBot
andauthored
Model connections (#43)
* Laravel 9 PHP 8 upgrade #major * Model specific connections added * Apply fixes from StyleCI Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent 0ded03d commit f329faa

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/Config/ModelConfig.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Support\Arr;
1010
use Illuminate\Support\Facades\Cache;
11-
use Illuminate\Support\Facades\DB;
12-
use Illuminate\Support\Facades\Schema;
1311

1412
class 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

Comments
 (0)