|
| 1 | +@php |
| 2 | + // Convert to arrays if they aren't already |
| 3 | + $fromValues = is_array($fromValue) ? $fromValue : (array)($fromValue ?? []); |
| 4 | + $toValues = is_array($toValue) ? $toValue : (array)($toValue ?? []); |
| 5 | + |
| 6 | + // Get added and removed values |
| 7 | + $added = []; |
| 8 | + $removed = []; |
| 9 | + |
| 10 | + foreach ($toValues as $value) { |
| 11 | + $found = false; |
| 12 | + foreach ($fromValues as $fromVal) { |
| 13 | + if (($value['id'] ?? $value) === ($fromVal['id'] ?? $fromVal)) { |
| 14 | + $found = true; |
| 15 | + break; |
| 16 | + } |
| 17 | + } |
| 18 | + if (!$found) { |
| 19 | + $added[] = $value; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + foreach ($fromValues as $value) { |
| 24 | + $found = false; |
| 25 | + foreach ($toValues as $toVal) { |
| 26 | + if (($value['id'] ?? $value) === ($toVal['id'] ?? $toVal)) { |
| 27 | + $found = true; |
| 28 | + break; |
| 29 | + } |
| 30 | + } |
| 31 | + if (!$found) { |
| 32 | + $removed[] = $value; |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + // Helper function to get display value |
| 37 | + $getDisplayValue = function($item) { |
| 38 | + if (is_array($item)) { |
| 39 | + $color = $item['color'] ?? null; |
| 40 | + $name = $item['name'] ?? $item['title'] ?? 'Unknown'; |
| 41 | + return $color ? "`{$name}`" : $name; |
| 42 | + } |
| 43 | + return $item; |
| 44 | + }; |
| 45 | +@endphp |
| 46 | + |
| 47 | +@if(count($added) > 0 || count($removed) > 0) |
| 48 | + **`{{ $fieldName }}`** has been updated: |
| 49 | + |
| 50 | + @if(count($added) > 0) |
| 51 | + - Added: {!! implode(', ', array_map($getDisplayValue, $added)) !!} |
| 52 | + @endif |
| 53 | + |
| 54 | + @if(count($removed) > 0) |
| 55 | + - Removed: {!! implode(', ', array_map($getDisplayValue, $removed)) !!} |
| 56 | + @endif |
| 57 | +@elseif(empty($toValues)) |
| 58 | + All values have been removed from **`{{ $fieldName }}`**. |
| 59 | +@else |
| 60 | + **`{{ $fieldName }}`** has been set to: {!! implode(', ', array_map($getDisplayValue, $toValues)) !!} |
| 61 | +@endif |
0 commit comments