Displaying 'New' and 'Old' Changes from Spatie Activity Log in an InfoList
Hello everyone! 
I'm using the Spatie Activity Log package in my Laravel project to track model changes. The package logs the 'new' and 'old' values of the changed attributes in the
I'm facing an issue with displaying these values in a user-friendly way in my InfoList component. I want to compare the 'old' and 'new' values side by side.
Here's what I have so far:
My question is: How can I efficiently parse and display this data in an InfoList? I'm looking for a way to iterate over the 'attributes' and 'old' arrays within the
Any suggestions or examples of how you've tackled a similar situation would be greatly appreciated!
Thank you in advance!
I'm using the Spatie Activity Log package in my Laravel project to track model changes. The package logs the 'new' and 'old' values of the changed attributes in the
properties field, and this data is stored as a collection.I'm facing an issue with displaying these values in a user-friendly way in my InfoList component. I want to compare the 'old' and 'new' values side by side.
Here's what I have so far:
- I've set up the Activity Log, and it's working fine; changes are being logged correctly.
- I can access the
propertiesfield in my activity log model, which gives me a collection containing 'new' and 'old' values.
My question is: How can I efficiently parse and display this data in an InfoList? I'm looking for a way to iterate over the 'attributes' and 'old' arrays within the
properties collection and present them in a tabular or side-by-side format for easy comparison.Any suggestions or examples of how you've tackled a similar situation would be greatly appreciated!
Thank you in advance!
Solution
I found solution myself it was really simple
KeyValueEntry::make('properties.attributes')
->label('New Value')
->columnSpan(2),
KeyValueEntry::make('properties.old')
->label('Old Value')
->visible(fn (Activity $record) => $record->properties->has('old'))
->columnSpan(2),
KeyValueEntry::make('properties.attributes')
->label('New Value')
->columnSpan(2),
KeyValueEntry::make('properties.old')
->label('Old Value')
->visible(fn (Activity $record) => $record->properties->has('old'))
->columnSpan(2),