@extends('layouts.admin') @section('title', '操作日誌') @section('content')

操作日誌

@forelse($logs as $log) @empty @endforelse
時間 用戶 動作 描述 變更內容
{{ $log->created_at->format('m-d H:i') }} {{ $log->user?->name ?? '系統' }} @php $badge = match ($log->action) { 'created' => 'success', 'updated' => 'warning', 'deleted' => 'danger', default => 'secondary', }; $label = match ($log->action) { 'created' => '新增', 'updated' => '更新', 'deleted' => '刪除', default => $log->action, }; @endphp {{ $label }} {{ $log->description }} @if($log->properties && isset($log->properties['new']))
查看變更
@foreach($log->properties['new'] as $field => $newValue)
{{ $field }}: {{ old_field_value($log, $field) }} → {{ mb_substr(json_encode($newValue, JSON_UNESCAPED_UNICODE), 1, -1) }}
@endforeach
@endif
沒有符合的日誌記錄
@endsection @php /** * 從 properties['old'] 取出舊值顯示(新視圖變數無法傳入 helper,直接 closure 處理) */ function old_field_value($log, $field) { $old = $log->properties['old'][$field] ?? null; $encoded = json_encode($old, JSON_UNESCAPED_UNICODE); return $old === null ? '空值' : mb_substr($encoded, 1, -1); } @endphp