Fix activity log properties for Spatie v5 attribute_changes#186
Conversation
Merge attribute_changes with properties in ActivityLogController so the Properties modal and detail page receive attributes/old again. Spatie laravel-activitylog v5 stores model diffs in attribute_changes, not properties. Add feature tests for the properties JSON endpoint. Made-with: Cursor
There was a problem hiding this comment.
Code Review
This pull request updates the ActivityLogController to correctly merge Spatie v5 model attribute changes with custom properties, ensuring that legacy and new data formats are handled consistently. I have reviewed the changes and the accompanying feature test; the test case for merging overlapping keys should be updated to explicitly include a collision to verify the merge logic as described in the test name.
| 'properties' => [ | ||
| 'note' => 'extra', | ||
| ], |
There was a problem hiding this comment.
The test name merges custom properties with attribute_changes with changes winning overlapping keys suggests it tests for key collisions, but the current implementation of the test does not have any overlapping keys between properties and attribute_changes. To make the test more robust and match its description, you should add an overlapping key to the properties array. This will ensure the merge precedence is correctly tested.
'properties' => [
'attributes' => ['title' => 'Should be overwritten'],
'note' => 'extra',
],
Summary
The activity log Properties modal and detail page stopped showing changed attributes after upgrading to spatie/laravel-activitylog v5, which stores model diffs in the
attribute_changescolumn. The dashboard only readproperties, which is now reserved for customwithProperties()data.Changes
attribute_changeswithpropertiesinActivityLogControllerfor the JSON properties endpoint and the Inertia show payload (legacy rows that still usepropertiesfor attributes/old remain supported).ActivityLogPropertiesTestcovering the merge behavior.Testing
php artisan test --compact tests/Feature/ActivityLogPropertiesTest.phpMade with Cursor