Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Revert PR #74 since the getDirty() Model method, in the saved event, should return an empty array (the model was saved; attributes are no longer dirty).
I also fixed Model getChanges()
@yormy
getChanges() is what should be used to know which fields were updated.
the returned array contains the attribute name that was updated as the key and the new value as the value.
To get the previous value of those fields, we need to catch them in the saving event first. Then in the saved event, we can use them and compare them to the newly saved value.
Spatie ActivityLog does it this way.
@see https://github.com/spatie/laravel-activitylog/blob/2b3f96c1a5fe3b265197e09cbed813efc96fb6e8/src/Traits/LogsActivity.php#L43
Previously, getChanges contained all the encrypted fields even when none were updated.
(the reason is that the changes attributes was updated AFTER then encryption of the attributes had happened; all the encrypted field values were encrypted and they are different compared to the unencrypted value)
Now, they will only appear if they were updated. Also, their value will be the unencrypted one. Previously, the encrypted value was returned, which is of no use in an event listener.