Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Sep 23, 2024
1 parent 70b4729 commit 6b95d9f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ public function setAttribute($key, $value)
return parent::setAttribute($key, $value);
}

/**
* @see \Illuminate\Database\Eloquent\Concerns\HasAttributes::originalIsEquivalent()
*
* @param string $key
* @return bool
*/
#[\Override]
public function originalIsEquivalent($key)
{
if (
isset($this->attributes[$key])
&& isset($this->original[$key])
&& is_subclass_of(($this->getCasts()[$key] ?? ''), \AnourValar\LaravelAtom\Mapper::class)
) {
return json_decode($this->attributes[$key], true) === json_decode($this->original[$key], true);
}

return parent::originalIsEquivalent($key);
}

/**
* @see \Illuminate\Database\Eloquent\Concerns\HasAttributes::asJson()
*
Expand All @@ -109,6 +129,7 @@ public function setAttribute($key, $value)
#[\Override]
protected function asJson($value)
{
// @TODO: {"foo":"bar"} -> {"foo": "bar"} ?
return json_encode($value, JSON_UNESCAPED_UNICODE); // for "json" columns
}

Expand Down

0 comments on commit 6b95d9f

Please sign in to comment.