@@ -63,12 +63,15 @@ public function getCreatedEventAttributes(): array
63
63
*/
64
64
public function getUpdatedEventAttributes (): array
65
65
{
66
+ $ new = [];
66
67
$ old = $ this ->getOldAttributes ();
67
- $ new = $ this ->getLoggedAttributeValues ();
68
68
69
- $ new = array_diff_uassoc ($ new , $ old , function ($ new , $ old ) {
70
- return $ new <=> $ old ;
71
- });
69
+ foreach ($ this ->getLoggedAttributeValues () as $ key => $ value ) {
70
+ if (!$ this ->oldIsEquivalent ($ key , $ value )) {
71
+ $ new [$ key ] = $ value ;
72
+ }
73
+ }
74
+
72
75
$ old = array_intersect_key ($ old , $ new );
73
76
74
77
return [
@@ -77,6 +80,35 @@ public function getUpdatedEventAttributes(): array
77
80
];
78
81
}
79
82
83
+ /**
84
+ * Determine if the new and old value for a given key are equivalent.
85
+ *
86
+ * @return bool
87
+ */
88
+ protected function oldIsEquivalent ($ key , $ new ): bool
89
+ {
90
+ if (! array_key_exists ($ key , $ this ->oldAttributes )) {
91
+ return false ;
92
+ }
93
+
94
+ $ original = $ this ->oldAttributes [$ key ];
95
+
96
+ if ($ new === $ original ) {
97
+ return true ;
98
+ } elseif (is_null ($ new )) {
99
+ return false ;
100
+ } elseif ($ this ->isDateAttribute ($ key )) {
101
+ return $ this ->fromDateTime ($ new ) ===
102
+ $ this ->fromDateTime ($ original );
103
+ } elseif ($ this ->hasCast ($ key )) {
104
+ return $ this ->castAttribute ($ key , $ new ) ===
105
+ $ this ->castAttribute ($ key , $ original );
106
+ }
107
+
108
+ return is_numeric ($ new ) && is_numeric ($ original )
109
+ && strcmp ((string ) $ new , (string ) $ original ) === 0 ;
110
+ }
111
+
80
112
/**
81
113
* Get the attributes for the deleted event.
82
114
*
0 commit comments