mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 15:34:04 +00:00
Correct encrypted castable logic
This commit is contained in:
parent
b0d5dad3fd
commit
4510275ec1
1 changed files with 6 additions and 3 deletions
|
|
@ -34,12 +34,15 @@ trait VirtualColumn
|
||||||
return;
|
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) {
|
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;
|
$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