@extends('layouts.dashboard') @section('page_title', 'ACTIVITY LOGS') @section('content')
SYSTEM ACTIVITY LOGS
@foreach ($logs as $key => $log) @php $oldValues = is_array($log->changes['old'] ?? null) ? $log->changes['old'] : []; $newValues = is_array($log->changes['new'] ?? null) ? $log->changes['new'] : []; $hiddenFields = ['id', 'created_at', 'updated_at', 'deleted_at', 'remember_token', 'password', 'google2fa_secret', 'email_verified_at']; $changedFields = collect(array_unique(array_merge(array_keys($oldValues), array_keys($newValues)))) ->reject(fn ($field) => in_array($field, $hiddenFields, true)) ->values(); $activitySummary = $log->activity_headline; if ($log->action === 'updated' && $changedFields->isNotEmpty()) { $labelMap = [ 'theme' => 'theme', 'two_factor_enabled' => 'two-factor login', 'name' => 'name', 'email' => 'email', ]; $formatValue = function ($value, $field = null): string { return \App\Support\Format\AmountFormatter::formatDisplayValue($value, is_string($field) ? $field : null); }; if ($changedFields->count() === 1) { $field = $changedFields->first(); $label = $labelMap[$field] ?? strtolower(str_replace('_', ' ', $field)); $old = $formatValue($oldValues[$field] ?? null, $field); $new = $formatValue($newValues[$field] ?? null, $field); $activitySummary = "{$log->actor_label} changed {$label} from {$old} to {$new}"; } else { $labels = $changedFields->take(3)->map( fn ($field) => $labelMap[$field] ?? strtolower(str_replace('_', ' ', $field)) )->implode(', '); $remaining = $changedFields->count() - 3; $activitySummary = $remaining > 0 ? "{$log->actor_label} updated {$labels} and {$remaining} more fields" : "{$log->actor_label} updated {$labels}"; } } @endphp @endforeach
No User Action Activity Module IP Address Date & Time Changes
{{ $logs->firstItem() + $key }}
User
{{ $log->user->name ?? 'System' }}
@php $badgeClass = match($log->action) { 'created' => 'ff-done', 'updated' => 'ff-transit', 'deleted' => 'ff-delayed', default => 'ff-pending' }; @endphp {{ $log->action_label }}
{{ $activitySummary }}
@if($log->entity_name) Record: {{ $log->entity_name }} @elseif($log->model_id) Record ID: #{{ $log->model_id }} @endif
{{ $log->model_label }} {{ $log->ip_address }} {{ $log->created_at->format('M d, Y h:i A') }} @if($log->changes) @else {{ $log->change_summary }} @endif
{!! $logs->links('pagination::bootstrap-5') !!}
@push('styles') @endpush @endsection