1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 08:24:04 +00:00

Use $model instead of static where possible

This commit is contained in:
lukinovec 2023-10-13 08:46:50 +02:00
parent cbd0b9221f
commit 5c33e250dd

View file

@ -33,14 +33,14 @@ trait VirtualColumn
} }
$encryptedCastables = array_merge( $encryptedCastables = array_merge(
static::$customEncryptedCastables, $model::$customEncryptedCastables,
['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables ['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables
); );
foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) { foreach ($model->getAttribute($model->getDataColumn()) ?? [] as $key => $value) {
$attributeHasEncryptedCastable = in_array(data_get($model->getCasts(), $key), $encryptedCastables); $attributeHasEncryptedCastable = in_array(data_get($model->getCasts(), $key), $encryptedCastables);
if ($attributeHasEncryptedCastable && static::valueEncrypted($value)) { if ($attributeHasEncryptedCastable && $model->valueEncrypted($value)) {
$model->attributes[$key] = $value; $model->attributes[$key] = $value;
} else { } else {
$model->setAttribute($key, $value); $model->setAttribute($key, $value);
@ -49,7 +49,7 @@ trait VirtualColumn
$model->syncOriginalAttribute($key); $model->syncOriginalAttribute($key);
} }
$model->setAttribute(static::getDataColumn(), null); $model->setAttribute($model->getDataColumn(), null);
$model->dataEncoded = false; $model->dataEncoded = false;
} }
@ -60,7 +60,7 @@ trait VirtualColumn
return; return;
} }
$dataColumn = static::getDataColumn(); $dataColumn = $model->getDataColumn();
$customColumns = $model->getCustomColumns(); $customColumns = $model->getCustomColumns();
$attributes = array_filter($model->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY); $attributes = array_filter($model->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);