@extends('layout.app') @section('content')
| Date | Action | Edit By | Old Data | New Data | @foreach ($list as $log) @php $action = $log->log_action ?? 'update'; // Long values (an old JSON blob) show a readable head, full text on hover. $show = function ($value) { $text = is_array($value) || is_object($value) ? json_encode($value) : (string) ($value ?? ''); return ['full' => $text, 'short' => \Illuminate\Support\Str::limit($text, 120)]; }; // 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); }; $old = (array) json_decode($log->old_info, true); $new = (array) json_decode($log->new_info, true); // A delete keeps the whole record in old_info — there is nothing to // diff it against, so show it as-is instead of a field comparison. if ($action === 'delete') { $change_old = collect($old)->except(['updated_at'])->reject($isRowDump)->all(); $change_new = []; } else { $change_old = []; $change_new = []; foreach ($old as $key => $value) { $newValue = $new[$key] ?? null; if ($isRowDump($value) || $isRowDump($newValue)) { continue; } if ($value != $newValue && $key != 'updated_at') { $change_old[$key] = $value; $change_new[$key] = $newValue; } } } @endphp||||
|---|---|---|---|---|---|---|---|---|
| {{ $log->created_at->format('d-m-Y H:i:s') }} | @if ($action === 'delete') Deleted @else Updated @endif | {{ $log->user->name ?? '' }} | @if ($change_old)
|
@endif
@if ($change_new)
|
@endif