Skip to content

Commit a01e158

Browse files
committed
updated originalIsEquivalent
1 parent f02e13d commit a01e158

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/Jenssegers/Mongodb/Eloquent/Model.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,41 +225,42 @@ public function getCasts()
225225
return $this->casts;
226226
}
227227

228+
228229
/**
229-
* @inheritdoc
230+
* Determine if the new and old values for a given key are equivalent.
231+
*
232+
* @param string $key
233+
* @return bool
230234
*/
231-
public function originalIsEquivalent($key, $current)
235+
public function originalIsEquivalent($key)
232236
{
233-
if (!array_key_exists($key, $this->original)) {
237+
if (! array_key_exists($key, $this->original)) {
234238
return false;
235239
}
236240

237-
$original = $this->getOriginal($key);
241+
$attribute = Arr::get($this->attributes, $key);
242+
$original = Arr::get($this->original, $key);
238243

239-
if ($current === $original) {
244+
if ($attribute === $original) {
240245
return true;
241-
}
242-
243-
if (null === $current) {
246+
} elseif (is_null($attribute)) {
244247
return false;
245-
}
246-
247-
if ($this->isDateAttribute($key)) {
248-
$current = $current instanceof UTCDateTime ? $this->asDateTime($current) : $current;
248+
} elseif ($this->isDateAttribute($key)) {
249+
$attribute = $attribute instanceof UTCDateTime ? $this->asDateTime($attribute) : $attribute;
249250
$original = $original instanceof UTCDateTime ? $this->asDateTime($original) : $original;
250251

251-
return $current == $original;
252-
}
253-
254-
if ($this->hasCast($key)) {
255-
return $this->castAttribute($key, $current) ===
252+
return $attribute == $original;
253+
} elseif ($this->hasCast($key, static::$primitiveCastTypes)) {
254+
return $this->castAttribute($key, $attribute) ==
256255
$this->castAttribute($key, $original);
257256
}
258257

259-
return is_numeric($current) && is_numeric($original)
260-
&& strcmp((string) $current, (string) $original) === 0;
258+
return is_numeric($attribute) && is_numeric($original)
259+
&& strcmp((string) $attribute, (string) $original) === 0;
261260
}
262261

262+
263+
263264
/**
264265
* Remove one or more fields.
265266
* @param mixed $columns

0 commit comments

Comments
 (0)