From b0e454e110612803536d02c37234ccf5a7629db6 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 8 Aug 2023 15:50:55 +0200 Subject: [PATCH] Handle custom castables in VirtualColumn --- src/VirtualColumn.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/VirtualColumn.php b/src/VirtualColumn.php index 653146a..aadc80d 100644 --- a/src/VirtualColumn.php +++ b/src/VirtualColumn.php @@ -37,7 +37,12 @@ trait VirtualColumn $defaultEncryptedCastables = ['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object']; foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) { - if ($model->hasCast($key, array_merge($defaultEncryptedCastables, static::$customEncryptedCastables)) && static::valueEncrypted($value)) { + $keyHasEncryptedCastable = $model->hasCast($key, array_merge( + $defaultEncryptedCastables, + array_map(fn (string $castable) => strtolower($castable), static::$customEncryptedCastables) // hasCast() only works correctly with lowercase strings + )); + + if ($keyHasEncryptedCastable && static::valueEncrypted($value)) { $model->attributes[$key] = $value; } else { $model->setAttribute($key, $value);