1
0
Fork 0
mirror of https://github.com/archtechx/virtualcolumn.git synced 2025-12-12 06:44:05 +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(
static::$customEncryptedCastables,
$model::$customEncryptedCastables,
['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);
if ($attributeHasEncryptedCastable && static::valueEncrypted($value)) {
if ($attributeHasEncryptedCastable && $model->valueEncrypted($value)) {
$model->attributes[$key] = $value;
} else {
$model->setAttribute($key, $value);
@ -49,7 +49,7 @@ trait VirtualColumn
$model->syncOriginalAttribute($key);
}
$model->setAttribute(static::getDataColumn(), null);
$model->setAttribute($model->getDataColumn(), null);
$model->dataEncoded = false;
}
@ -60,7 +60,7 @@ trait VirtualColumn
return;
}
$dataColumn = static::getDataColumn();
$dataColumn = $model->getDataColumn();
$customColumns = $model->getCustomColumns();
$attributes = array_filter($model->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);