-
Hello, I am looking at: https://spatie.be/docs/laravel-activitylog/v3/advanced-usage/logging-model-events#logging-directly-related-model-attributes I set my model up as such: use LogsActivity;
protected static $logName = 'audit';
protected static $logOnlyDirty = true;
protected static $submitEmptyLogs = false;
protected static $ignoreChangedAttributes = ['updated_at', 'created_at'];
protected static $logAttributes = [
...
'address.address_1',
'address.address_2',
...
];
public function address()
{
return $this->hasOne(Address::class);
} I am storing changes on the controller as such: $edit = DB::transaction(
function() use ($request, $store, $data) {
$store->update($data);
$store->address()->update($request->address);
}
); When I make changes, the address attributes do not appear in the log. What am I doing wrong and also, what is the benefit to using the dot notation on the parent model rather than giving the child model the Many thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey, the related model attribute logging isn't meant/thought to log changes on multiple models but to log data from a related model that's important for the log context. If you ONLY change the address in this place you could change the order of update queries which should lead to the updated address in the product log entry. |
Beta Was this translation helpful? Give feedback.
-
Okay, thank you for taking the time to reply. It is much clearer to me now. |
Beta Was this translation helpful? Give feedback.
Hey,
the related model attribute logging isn't meant/thought to log changes on multiple models but to log data from a related model that's important for the log context.
Just an explicit use-case: you have a
Product
andProductCode
model to split logic and keep the product model itself cleaner. But the product code is very important so you want to have it in every log as it's also the human-readable product identifier.If you ONLY change the address in this place you could change the order of update queries which should lead to the updated address in the product log entry.
But I would really recommend to use dedicated logs and let the address model log its own activities. By using some el…