mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 17:04:04 +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;
|
||||
}
|
||||
|
||||
foreach ($model->getAttributes() as $key => $value) {
|
||||
if (! in_array($key, static::getCustomColumns())) {
|
||||
$current = $model->getAttribute(static::getDataColumn()) ?? [];
|
||||
$dataColumn = static::getDataColumn();
|
||||
$customColumns = static::getCustomColumns();
|
||||
$attributes = array_filter($model->getAttributes(), fn ($key) => ! in_array($key, $customColumns), ARRAY_FILTER_USE_KEY);
|
||||
|
||||
$model->setAttribute(static::getDataColumn(), array_merge($current, [
|
||||
$key => $value,
|
||||
]));
|
||||
// Remove data column from the attributes
|
||||
unset($attributes[$dataColumn]);
|
||||
|
||||
unset($model->attributes[$key]);
|
||||
unset($model->original[$key]);
|
||||
}
|
||||
foreach ($attributes as $key => $value) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue