mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 21:34:05 +00:00
Handle custom castables in VirtualColumn
This commit is contained in:
parent
de9d9d7cab
commit
b0e454e110
1 changed files with 6 additions and 1 deletions
|
|
@ -37,7 +37,12 @@ trait VirtualColumn
|
||||||
$defaultEncryptedCastables = ['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'];
|
$defaultEncryptedCastables = ['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'];
|
||||||
|
|
||||||
foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
|
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;
|
$model->attributes[$key] = $value;
|
||||||
} else {
|
} else {
|
||||||
$model->setAttribute($key, $value);
|
$model->setAttribute($key, $value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue