@extends('layout.app') @section('content')

{{ $meta['label'] }} — Edit & Delete Log

@forelse ($logs as $log) @php $action = $log->log_action ?? 'update'; $old = (array) json_decode($log->old_info, true); $new = (array) json_decode($log->new_info, true); // A relation dumped into an old log row (a list of related rows) is // never a real field change — the two sides could never match, so it // showed up as "changed" on every edit. Skip it; a JSON column holding // plain values (a list of ids, say) is a real change and stays. $isRowDump = function ($value) { if (! is_array($value) || $value === []) { return false; } $first = reset($value); return is_array($first) || is_object($first); }; // A delete keeps the full record in old_info; an edit is shown // as the fields that actually changed. $changes = []; if ($action === 'delete') { foreach (collect($old)->except(['updated_at', 'created_at', 'deleted_at'])->all() as $key => $value) { if ($value !== null && $value !== '' && ! $isRowDump($value)) { $changes[$key] = ['old' => $value, 'new' => null]; } } } else { foreach ($old as $key => $value) { $newValue = $new[$key] ?? null; if ($isRowDump($value) || $isRowDump($newValue)) { continue; } if ($value != $newValue && $key != 'updated_at') { $changes[$key] = ['old' => $value, 'new' => $newValue]; } } } @endphp @empty @endforelse
# Date Record Action By Changes
{{ $loop->iteration + ($logs->currentPage() - 1) * $logs->perPage() }} {{ $log->created_at ? $log->created_at->format('d-m-Y H:i:s') : '-' }} #{{ $log->log_id }} @if ($action === 'delete') Deleted @else Edited @endif {{ optional($log->user)->name ?? '-' }} @if (empty($changes)) — @else @foreach ($changes as $field => $pair) @php // Log rows written before the change log was trimmed can hold a // whole relation dumped as JSON — show a readable head of it, // full text on hover. $oldText = is_array($pair['old']) || is_object($pair['old']) ? json_encode($pair['old']) : (string) ($pair['old'] ?? ''); $newText = is_array($pair['new']) || is_object($pair['new']) ? json_encode($pair['new']) : (string) ($pair['new'] ?? ''); @endphp @endforeach
Field Old New
{{ $field }} {{ $oldText === '' ? '—' : \Illuminate\Support\Str::limit($oldText, 120) }} {{ $newText === '' ? '—' : \Illuminate\Support\Str::limit($newText, 120) }}
@endif
No log entry found.
{{ $logs->links() }}
@endsection @section('ajax') @endsection