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

[8.x] Loose comparison causes the value not to be saved #42793

Merged
merged 1 commit into from
Jun 13, 2022
Merged

[8.x] Loose comparison causes the value not to be saved #42793

merged 1 commit into from
Jun 13, 2022

Conversation

vsg24
Copy link
Contributor

@vsg24 vsg24 commented Jun 13, 2022

The PR back-ports #41337 to 8.x branch.

The description below is copied from the original PR.

Given an attribute with the cast object or collection, the $model->isDirty() method returns the wrong value due to the use of loose comparison.

Example from issue #37961:

use Illuminate\Database\Eloquent\Model;

class Test extends Model
{
    protected $casts = [
        'collection' => 'collection',
    ];
    protected $fillable = [
        'collection',
    ];
}

$model = new Test(['collection' => ['key' => true]]);
$model->syncOriginal();
$model->fill(['collection' => ['key' => 'value']]);

$model->isDirty(); // false but should be true

// or
$model = new Test(['collection' => ['key' => null]]);
$model->syncOriginal();
$model->fill(['collection' => ['key' => false]]);

$model->isDirty(); // false but should be true

@taylorotwell taylorotwell merged commit a02b1a3 into laravel:8.x Jun 13, 2022
@vsg24 vsg24 deleted the 8.x branch June 13, 2022 18:36
Copy link
Contributor

@MasterRO94 MasterRO94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR breaks BC. If original $value is null then PHP Deprecated: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated is thrown

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