Skip to content

Might not want to use $model->unset('attribute_or_model') #1184

Closed
@MatthewDrouin

Description

@MatthewDrouin

While testing we have determined that if you do

$model->attribute = 'blah';
$model->save();

$model->unset('attribute');
$model->isDity(); // will return false

however if you set it to null

$model->attribute = 'blah';
$model->save();

$model->attribute = null;
$model->isDity(); // will return true

The reason for this is that isDirty() calls getDirty() https://github.com/laravel/framework/blob/5.3/src/Illuminate/Database/Eloquent/Model.php#L3220 which loops over the current attributes. If the attribute is unset then it will not look at it.

So if you want to know if your object isDirty() you really should use null unless a trait or something is used with unset to mark it as dirty.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions