Thanks for the great project, I wanted to know, does it supports to log changes in JOSN field type, I have tried following but it didn't work.
use LogsActivity;
protected static $logAttributes = ['name', 'in_short', 'meta->progress'];
Keep up the great work 馃憤
That isn't supported atm, I'd accept a PR if the code to makes this work is simple.
It logs json fields as empty, even with changes. Is this expected behaviour ?
model configuration
use LogsActivity;
protected static $logAttributes = ['*'];
@rjcrystal could you please open a new issue? Even if they kind of belong to each other the original topic is a feature request and your's is a bug/question.
@saqueib I've reopened this issue to keep it in the feature request line. But I can't promise when or even that it will come.
Hi @Gummibeer, I would like to work on this feature/issue.
Would you be able to give me some direction as to the files that this would be preferred to be implemented in?
I have found references to the $logAttributes variable in Spatie\Activitylog\Traits\DetectChanges trait, don't know if this would be where you guys would like this?
Also, I have also noticed, that when saving a field that is of JSON type, Laravel will parse it and add spaces if it was saved without them, and when you save you will have an entry related to the JSON column that actually doesn't have changes. This may be related to this and I have implemented a way to fix that before, although may be made a bit more elegant for this package.
@ReeceM happy to hear this! 馃槉
I think that it should be added via a new method called in https://github.com/spatie/laravel-activitylog/blob/89bbdbea8f085d72ba7513af989e2e54366f5794/src/Traits/DetectsChanges.php#L120-L143
Something like the already implemented date serialization.
If you need any more details just ask. Or if you have some code just open the PR and we will discuss it.
@Gummibeer, awesome, thank you.
I will have a look at adding it there as a new method then 馃憤 .
I will also ask for more details too probably :)
Hi @Gummibeer, if this is added for to log a specific attribute, would it also be preferred to be able to ignore a specific attribute in the JSON ?
I don't think the below would account for ignoring keys in a JSON object/array
To keep the scope simple I would like to stick to exactly what the issue author requested.
So only add a JSON attribute sub-key. What I've forgot. The main attribute has to be used in method that collects all attributes to log.
And it would be awesome if the logOnlyDirty works with the JSON attributes.
I would also be fine with a limit of depth. So that it's only possible to access the first level of JSON attributes.
Okay, I won't account for ignoring, would that be welcomed as a separate feature addition?
With the depth, I have managed to make it go as far down as put in the sub-key of the $logAttributes.
In terms of the logOnlyDirty, is that for when it is included in $logAttributes or for any JSON that is put into the model?
As a separate it's welcomed. But I would like to keep the hacktoberfest PRs simple to review and merge them fast.
I mean this: https://docs.spatie.be/laravel-activitylog/v3/advanced-usage/logging-model-events/#logging-only-the-changed-attributes
So that if it's enabled and attribute has changed in total but attribute->subkey didn't it won't log it. But also with this I would be fine with a new PR or that's a limitation of the feature.
Okay, so far from what I can tell is that it won't update the whole attribute when the sub-key hasn't changed.
I will write some tests to account for this addition for the changes.