-
Notifications
You must be signed in to change notification settings - Fork 39
Description
Bug Description
The key-value.blade.php view throws an error when trying to display audit logs that contain nested arrays with primitive values (strings, numbers, etc.).
Error Message
Cannot access offset of type string on string
Root Cause
The issue is in /vendor/tapp/filament-auditing/resources/views/tables/columns/key-value.blade.php at line 18:
{{$nestedValue['id']}}The code incorrectly assumes that if a value is an array, it's always an array of objects with an id key. However, in many audit log scenarios, we have nested arrays where the values are strings or other primitive types.
Example Scenario
When audit log contains data like:
[
'addresses' => [
'street' => 'Main Street',
'city' => 'Berlin'
]
]The code iterates through the array, but $nestedValue becomes a string ('Main Street'), and attempting to access $nestedValue['id'] causes the error.
Steps to Reproduce
- Create an Auditable model with nested array attributes
- Update the model with nested data structure (e.g., addresses with street and city)
- Try to view the audit log in Filament
- The error occurs when rendering the key-value column
Expected Behavior
The view should handle different types of nested values:
- Arrays of objects (current behavior)
- Arrays with string/numeric keys and primitive values
- Mixed nested structures
Solution
Replace the content of key-value.blade.php with:
@php
$data = isset($state) ? $state : $getState();
@endphp
<div class="my-2 text-sm font-medium tracking-tight">
<ul>
@foreach ($data ?? [] as $key => $value)
<li>
<span class="inline-block rounded-md whitespace-normal text-gray-700 dark:text-gray-200 bg-gray-500/10">
{{ Str::title($key) }}:
</span>
<span class="font-semibold">
@unless (is_array($value))
{{ $value }}
@else
<span class="divide-x divide-solid divide-gray-200 dark:divide-gray-700">
@foreach ($value as $nestedKey => $nestedValue)
@if (is_array($nestedValue) && isset($nestedValue['id']))
{{ $nestedValue['id'] }}
@elseif(is_array($nestedValue))
{{ $nestedKey }}: {{ json_encode($nestedValue) }}
@else
{{ is_numeric($nestedKey) ? $nestedValue : "$nestedKey: $nestedValue" }}
@endif
@if (!$loop->last)
,
@endif
@endforeach
</span>
@endunless
</span>
</li>
@endforeach
</ul>
</div>This fix properly handles:
- Objects with
idkeys (original behavior maintained) - Nested arrays (displayed as JSON)
- String/numeric values with proper key-value formatting
- Numeric keys (displayed without the key prefix)
Temporary Workaround
Until this is fixed in the package, you can publish and override the view:
php artisan vendor:publish --tag=filament-auditing-viewsThen replace the content of resources/views/vendor/filament-auditing/tables/columns/key-value.blade.php with the fix above.