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

Revert static -> $model changes

This commit is contained in:
lukinovec 2023-10-17 05:59:52 +02:00
parent 4c90064977
commit b573ec6cb9

View file

@ -33,14 +33,14 @@ trait VirtualColumn
}
$encryptedCastables = array_merge(
$model::$customEncryptedCastables,
static::$customEncryptedCastables,
['encrypted', 'encrypted:array', 'encrypted:collection', 'encrypted:json', 'encrypted:object'], // Default encrypted castables
);
foreach ($model->getAttribute($model->getDataColumn()) ?? [] as $key => $value) {
foreach ($model->getAttribute(static::getDataColumn()) ?? [] as $key => $value) {
$attributeHasEncryptedCastable = in_array(data_get($model->getCasts(), $key), $encryptedCastables);
if ($attributeHasEncryptedCastable && $model->valueEncrypted($value)) {
if ($attributeHasEncryptedCastable && static::valueEncrypted($value)) {
$model->attributes[$key] = $value;
} else {
$model->setAttribute($key, $value);
@ -49,7 +49,7 @@ trait VirtualColumn
$model->syncOriginalAttribute($key);
}
$model->setAttribute($model->getDataColumn(), null);
$model->setAttribute(static::getDataColumn(), null);
$model->dataEncoded = false;
}
@ -60,8 +60,8 @@ trait VirtualColumn
return;
}
$dataColumn = $model->getDataColumn();
$customColumns = $model->getCustomColumns();
$dataColumn = static::getDataColumn();
$customColumns = static::getCustomColumns();
$attributes = array_filter($model->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
// Remove data column from the attributes
@ -90,6 +90,13 @@ trait VirtualColumn
}
}
protected static function decodeAttributes(self $model)
{
$model->dataEncoded = true;
static::decodeVirtualColumn($model);
}
public static function bootVirtualColumn()
{
static::registerAfterListener('retrieved', function ($model) {
@ -127,6 +134,10 @@ trait VirtualColumn
{
$listeners = static::$afterListeners[$event] ?? [];
// $listeners = array_filter(static::$afterListeners[$event] ?? [], function ($listener) {
// return $listener[0] === static::class;
// });
if (! $event) {
return;
}