diff --git a/app/Livewire/MoleculeHistoryTimeline.php b/app/Livewire/MoleculeHistoryTimeline.php index f12a0364..e5c70752 100644 --- a/app/Livewire/MoleculeHistoryTimeline.php +++ b/app/Livewire/MoleculeHistoryTimeline.php @@ -19,16 +19,19 @@ public function getHistory() $audit_data[$index]['event'] = $audit->getMetadata()['audit_event']; $audit_data[$index]['created_at'] = date('Y/m/d', strtotime($audit->getMetadata()['audit_created_at'])); - if (str_contains('.', array_keys($audit->old_values)[0])) { - $old_key = $audit->old_values ? explode('.', array_keys($audit->old_values)[0])[0] : null; - $new_key = $audit->new_values ? explode('.', array_keys($audit->new_values)[0])[0] : null; - - $old_key = $old_key ?: $new_key; - $new_key = $new_key ?: $old_key; + $values = !empty($audit->old_values) ? $audit->old_values : $audit->new_values; + $first_affected_column = !empty($values) ? array_keys($values)[0] : null; + + if (str_contains($first_affected_column, '.')) { + $affected_column = explode('.', $first_affected_column)[0]; + + $audit_data[$index]['affected_columns'][$affected_column]['old_value'] = $audit->old_values ? array_values($audit->old_values)[0] : null; + $audit_data[$index]['affected_columns'][$affected_column]['new_value'] = $audit->new_values ? array_values($audit->new_values)[0] : null; } else { - foreach ($audit->getModified() as $key => $value) { - $audit_data[$index]['affected_columns'][$key]['old_value'] = $value['old'] ?: null; - $audit_data[$index]['affected_columns'][$key]['new_value'] = $value['new'] ?: null; + foreach ($audit->getModified() as $affected_column => $value) { + + $audit_data[$index]['affected_columns'][$affected_column]['old_value'] = array_key_exists('old', $value) ? $value['old'] : null; + $audit_data[$index]['affected_columns'][$affected_column]['new_value'] = array_key_exists('new', $value) ? $value['new'] : null; } } } @@ -42,7 +45,6 @@ public function getHistory() array_push($audit_data, $initial_audit); $this->audit_data = $audit_data; - // dd($audit_data); } public function render()