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] Fixes Model::isDirty() when AsCollection or AsEncryptedCollection have arguments #47235

Merged
merged 2 commits into from May 26, 2023

Conversation

nunomaduro
Copy link
Member

@nunomaduro nunomaduro commented May 26, 2023

This pull request addresses the issue with Model::isDirty() when using AsCollection or AsEncryptedCollection casters with arguments.

The problem arises when declaring the cast as AsCollection::class . ':' . CustomCollection::class, which generates a string that misleads Model::originalIsEquivalent into incorrectly evaluating the caster's behavior within a specific if condition:

// Cast: Illuminate\Database\Eloquent\Casts\AsCollection:Illuminate\Tests\Database\CustomCollection
// Before:
in_array($this->getCasts()[$key], [AsEncryptedArrayObject::class, AsEncryptedCollection::class]) // false...
// After:
Str::startsWith($this->getCasts()[$key], [AsEncryptedArrayObject::class, AsEncryptedCollection::class]) // true...

@nunomaduro nunomaduro changed the title [10.x] Fixes $model->isDirty when AsCollection caster have arguments [10.x] Fixes Model::isDirty when AsCollection or AsEncryptedCollection have arguments May 26, 2023
@nunomaduro nunomaduro changed the title [10.x] Fixes Model::isDirty when AsCollection or AsEncryptedCollection have arguments [10.x] Fixes Model::isDirty() when AsCollection or AsEncryptedCollection have arguments May 26, 2023
@taylorotwell taylorotwell merged commit 4774fef into 10.x May 26, 2023
18 checks passed
@taylorotwell taylorotwell deleted the fix/dirty-on-built-in-casters-with-arguments branch May 26, 2023 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants