@php $record = $getRecord(); $activities = \App\Models\ActivityLog::where('loggable_type', get_class($record)) ->where('loggable_id', $record->id) ->with('user') ->orderBy('created_at', 'desc') ->get(); $getIconConfig = function ($action, $properties) { if ($action === 'created') { return [ 'icon' => 'heroicon-o-plus-circle', 'bg' => '#f0fdf4', 'color' => '#16a34a', 'ring' => '#bbf7d0', ]; } if ($action === 'deleted') { return [ 'icon' => 'heroicon-o-trash', 'bg' => '#fff1f2', 'color' => '#e11d48', 'ring' => '#fecdd3', ]; } $attributes = $properties['attributes'] ?? []; if (isset($attributes['status'])) { return match ($attributes['status']) { 'pending' => ['icon' => 'heroicon-o-clock', 'bg' => '#eff6ff', 'color' => '#1d4ed8', 'ring' => '#bfdbfe'], 'processing' => ['icon' => 'heroicon-o-arrow-path', 'bg' => '#fffbeb', 'color' => '#b45309', 'ring' => '#fde68a'], 'shipped' => ['icon' => 'heroicon-o-truck', 'bg' => '#f0f9ff', 'color' => '#0369a1', 'ring' => '#bae6fd'], 'delivered' => ['icon' => 'heroicon-o-check-circle', 'bg' => '#f0fdf4', 'color' => '#16a34a', 'ring' => '#bbf7d0'], 'cancelled' => ['icon' => 'heroicon-o-x-circle', 'bg' => '#fff1f2', 'color' => '#e11d48', 'ring' => '#fecdd3'], default => ['icon' => 'heroicon-o-pencil-square', 'bg' => '#fafafa', 'color' => '#64748b', 'ring' => '#e2e8f0'], }; } if (isset($attributes['payment_status'])) { return match ($attributes['payment_status']) { 'paid' => ['icon' => 'heroicon-o-banknotes', 'bg' => '#f0fdf4', 'color' => '#16a34a', 'ring' => '#bbf7d0'], 'failed' => ['icon' => 'heroicon-o-exclamation-triangle','bg' => '#fff1f2', 'color' => '#e11d48', 'ring' => '#fecdd3'], 'refunded' => ['icon' => 'heroicon-o-arrow-uturn-left', 'bg' => '#eff6ff', 'color' => '#1d4ed8', 'ring' => '#bfdbfe'], default => ['icon' => 'heroicon-o-credit-card', 'bg' => '#fffbeb', 'color' => '#b45309', 'ring' => '#fde68a'], }; } return ['icon' => 'heroicon-o-pencil-square', 'bg' => '#fafafa', 'color' => '#64748b', 'ring' => '#e2e8f0']; }; $getStatusBadge = function ($value, $type = 'status') { if ($type === 'status') { [$bg, $color, $border, $label] = match (strtolower($value ?? '')) { 'pending' => ['#eff6ff', '#1d4ed8', '#bfdbfe', 'Pending'], 'processing' => ['#fffbeb', '#b45309', '#fde68a', 'Processing'], 'shipped' => ['#f0f9ff', '#0369a1', '#bae6fd', 'Shipped'], 'delivered' => ['#f0fdf4', '#15803d', '#bbf7d0', 'Delivered'], 'cancelled' => ['#fff1f2', '#be123c', '#fecdd3', 'Cancelled'], default => ['#f8fafc', '#475569', '#e2e8f0', ucfirst($value ?? '—')], }; } else { [$bg, $color, $border, $label] = match (strtolower($value ?? '')) { 'paid' => ['#f0fdf4', '#15803d', '#bbf7d0', 'Paid'], 'pending' => ['#eff6ff', '#1d4ed8', '#bfdbfe', 'Pending'], 'failed' => ['#fff1f2', '#be123c', '#fecdd3', 'Failed'], 'refunded' => ['#f0f9ff', '#0369a1', '#bae6fd', 'Refunded'], default => ['#f8fafc', '#475569', '#e2e8f0', ucfirst($value ?? '—')], }; } return "{$label}"; }; @endphp
@forelse ($activities as $index => $activity) @php $properties = $activity->properties ?? []; $iconConfig = $getIconConfig($activity->action, $properties); $isLast = $loop->last; $attrs = $properties['attributes'] ?? []; $old = $properties['old'] ?? []; // Build clean description $desc = $activity->description ?? ''; if ($activity->action === 'updated' && str_contains($desc, 'updated:')) { $desc = trim(explode('updated:', $desc)[0]) . ' updated'; } // Build diff items $diffs = []; if ($activity->action === 'updated' && !empty($attrs)) { foreach ($attrs as $field => $newVal) { $oldVal = $old[$field] ?? null; if ($oldVal === $newVal || $field === 'updated_at') continue; $diffs[] = ['field' => $field, 'old' => $oldVal, 'new' => $newVal]; } } @endphp
{{-- Left: icon + connector --}}
@if (!$isLast)
@endif
{{-- Right: content --}}
{{-- Header row --}}
{{ $activity->user?->name ?? 'System' }} @if ($activity->action === 'created') Created @elseif ($activity->action === 'updated') Updated @elseif ($activity->action === 'deleted') Deleted @endif
{{ $activity->created_at->diffForHumans() }}
{{-- Description --}}

{{ $desc }}

{{-- Diff pills --}} @if (!empty($diffs)) @php // Separate status/payment_status from other fields $statusDiffs = array_filter($diffs, fn($d) => in_array($d['field'], ['status', 'payment_status'])); $otherDiffs = array_filter($diffs, fn($d) => !in_array($d['field'], ['status', 'payment_status'])); $fmt = function ($v) { if (is_null($v)) return '—'; if (is_bool($v)) return $v ? 'true' : 'false'; $s = (string) $v; if (str_starts_with($s, '

') && str_ends_with($s, '

')) { $s = substr($s, 3, -4); } return trim($s); }; @endphp
{{-- Status + Payment Status: stacked block layout --}} @if (!empty($statusDiffs))
@foreach ($statusDiffs as $diff) @php $isPayment = ($diff['field'] === 'payment_status'); $type = $isPayment ? 'payment' : 'status'; @endphp
{{ $isPayment ? 'Payment Status' : 'Order Status' }}
{!! $getStatusBadge($fmt($diff['old']), $type) !!} {!! $getStatusBadge($fmt($diff['new']), $type) !!}
@endforeach
@endif {{-- Other field changes --}} @foreach ($otherDiffs as $diff)
{{ str_replace('_', ' ', $diff['field']) }}
{{ $fmt($diff['old']) }} {{ $fmt($diff['new']) }}
@endforeach
@endif
@empty

No activity recorded yet.

@endforelse