minaremonshaker's avatar

Understanding isClean() and isDirty() in Eloquent Models

I have a slight misunderstanding about the isClean() and isDirty() methods in Eloquent. I understand that isDirty() checks whether the model's attributes have been modified since it was retrieved. However, what I'm unclear about is how this comparison is actually performed behind the scenes.

0 likes
1 reply
Snapey's avatar
Snapey
Best Answer
Level 122

if you dd an eloquent model, you will see there are two arrays of model data. One called attributes, one called original.

When you call save on the model, only the attributes that have changed compared to original are saved.

isDirty() tells you if the two arrays differ. isClean() tells you they are the same.

1 like

Please or to participate in this conversation.