Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix getDirty method when using AsEnumArrayObject / AsEnumCollection #46561

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\Casts\AsEncryptedArrayObject;
use Illuminate\Database\Eloquent\Casts\AsEncryptedCollection;
use Illuminate\Database\Eloquent\Casts\AsEnumArrayObject;
use Illuminate\Database\Eloquent\Casts\AsEnumCollection;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\InvalidCastException;
use Illuminate\Database\Eloquent\JsonEncodingException;
Expand Down Expand Up @@ -2042,6 +2044,8 @@ public function originalIsEquivalent($key)
$this->castAttribute($key, $original);
} elseif ($this->isClassCastable($key) && in_array($this->getCasts()[$key], [AsArrayObject::class, AsCollection::class])) {
return $this->fromJson($attribute) === $this->fromJson($original);
} elseif ($this->isClassCastable($key) && Str::startsWith($this->getCasts()[$key], [AsEnumArrayObject::class, AsEnumCollection::class])) {
return $this->fromJson($attribute) === $this->fromJson($original);
} elseif ($this->isClassCastable($key) && $original !== null && in_array($this->getCasts()[$key], [AsEncryptedArrayObject::class, AsEncryptedCollection::class])) {
return $this->fromEncryptedString($attribute) === $this->fromEncryptedString($original);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function testDirtyOnEnumCollectionObject()
{
$model = new EloquentModelCastingStub;
$model->setRawAttributes([
'asEnumCollectionAttribute' => json_encode(['draft', 'pending']),
'asEnumCollectionAttribute' => '["draft", "pending"]',
]);
$model->syncOriginal();

Expand All @@ -335,7 +335,7 @@ public function testDirtyOnEnumArrayObject()
{
$model = new EloquentModelCastingStub;
$model->setRawAttributes([
'asEnumArrayObjectAttribute' => json_encode(['draft', 'pending']),
'asEnumArrayObjectAttribute' => '["draft", "pending"]',
]);
$model->syncOriginal();

Expand Down