mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 19:54:03 +00:00
Refactor encodeAttributes()
This commit is contained in:
parent
daeb8d8c86
commit
e411001251
1 changed files with 12 additions and 9 deletions
|
|
@ -60,19 +60,22 @@ trait VirtualColumn
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($model->getAttributes() as $key => $value) {
|
$dataColumn = static::getDataColumn();
|
||||||
if (! in_array($key, static::getCustomColumns())) {
|
$customColumns = static::getCustomColumns();
|
||||||
$current = $model->getAttribute(static::getDataColumn()) ?? [];
|
$attributes = array_filter($model->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
|
||||||
|
|
||||||
$model->setAttribute(static::getDataColumn(), array_merge($current, [
|
// Remove data column from the attributes
|
||||||
$key => $value,
|
unset($attributes[$dataColumn]);
|
||||||
]));
|
|
||||||
|
|
||||||
unset($model->attributes[$key]);
|
foreach ($attributes as $key => $value) {
|
||||||
unset($model->original[$key]);
|
// Remove attribute from the model
|
||||||
}
|
unset($model->attributes[$key]);
|
||||||
|
unset($model->original[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add attribute to the data column
|
||||||
|
$model->setAttribute($dataColumn, $attributes);
|
||||||
|
|
||||||
$model->dataEncoded = true;
|
$model->dataEncoded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue