From 29d1469651ec7dc69d7332505c0a5790535496e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 2 Apr 2024 20:25:17 +0200 Subject: [PATCH] use getAttribute() in HasDatabase to support encrypted columns --- src/Database/Concerns/HasDatabase.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Database/Concerns/HasDatabase.php b/src/Database/Concerns/HasDatabase.php index 48d1c406..e1f4a55f 100644 --- a/src/Database/Concerns/HasDatabase.php +++ b/src/Database/Concerns/HasDatabase.php @@ -20,7 +20,7 @@ trait HasDatabase /** @var TenantWithDatabase&Model $this */ $databaseConfig = []; - foreach ($this->getAttributes() as $key => $value) { + foreach (array_keys($this->getAttributes()) as $key) { if (str($key)->startsWith($this->internalPrefix() . 'db_')) { if ($key === $this->internalPrefix() . 'db_name') { // Remove DB name because we set that separately @@ -32,7 +32,9 @@ trait HasDatabase continue; } - $databaseConfig[str($key)->after($this->internalPrefix() . 'db_')->toString()] = $value; + // We use getAttribute() instead of getting the value directly from the attributes array + // to support encrypted columns and any other types of casts. + $databaseConfig[str($key)->after($this->internalPrefix() . 'db_')->toString()] = $this->getAttribute($key); } }