From 4510275ec1c0aa18299e6613e3a8c4781366c90e Mon Sep 17 00:00:00 2001 From: lukinovec Date: Wed, 9 Aug 2023 14:33:06 +0200 Subject: [PATCH] Correct encrypted castable logic --- src/VirtualColumn.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/VirtualColumn.php b/src/VirtualColumn.php index 511cc24..c68a0e6 100644 --- a/src/VirtualColumn.php +++ b/src/VirtualColumn.php @@ -34,12 +34,15 @@ trait VirtualColumn return; } - $defaultEncryptedCastables = ['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object']; + $encryptedCastables = array_merge( + static::$customEncryptedCastables, + ['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables + ); foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) { - $keyHasEncryptedCastable = ! empty(array_intersect($model->getCasts(), array_merge($defaultEncryptedCastables, static::$customEncryptedCastables))); + $attributeHasEncryptedCastable = in_array(data_get($model->getCasts(), $key), $encryptedCastables); - if ($keyHasEncryptedCastable && static::valueEncrypted($value)) { + if ($attributeHasEncryptedCastable && static::valueEncrypted($value)) { $model->attributes[$key] = $value; } else { $model->setAttribute($key, $value);