Draft: Feat/cache old attributes
Adding a trait that will allow easy access to non-encrypted from/to (before/after) values after model updates.
The trait: CacheOldAttributesTrait
Get changes: $changes = $model->getUpdatedAttributes();
Format:
array [
"first_name": [
"from": "Jane",
"to": "John"
],
"last_name": [
"from": "Smithe",
"to": "Smith"
],
]
All names are WIP and open to change.
Notes
Fuzzy Dirtiness
Currently the trait uses fuzzier checks than standard getDirty()
. Eg 5
> 5.0
will not be considered dirty. Perhaps this can be configured on a per-attribute basis. This is based off the updated value being cast to the same type
as the original value on the model. So false
on the model will match 0
as an updated value.
Return Format
Usually the return format is an array keyed by the field name with the values being an array with from
and to
values. Passing true
to the getUpdatedAttributes()
function will return the sub-array as json encoded for better compatibility with Spatie Activity Log.