How to verify if Laravel Model was Changed?

Detect model changes in Laravel using clean methods like wasChanged and isDirty. Improve performance, save conditions, and handle updates precisely.

|

Verifying if a model was changed in Laravel involves built-in Eloquent methods like isDirty(), wasChanged() and isClean(). Each helps determine whether an attribute was modified before or after saving.

These checks improve performance, prevent unnecessary database writes and help manage conditional logic inside controllers or services. Ready to see them in action?

Why You Might Need to Detect Model Changes?

Detecting model changes helps you avoid unnecessary database operations and write cleaner logic during updates.

  • Prevents redundant save() calls when nothing changed
  • Useful for audit trails or triggering events only on actual changes
  • Improves performance by skipping write-heavy operations
  • Helps validate user input more precisely during form submissions

Laravel Methods to Detect If a Model Has Changed

Laravel offers three built-in Eloquent methods isDirty(), wasChanged() and isClean() to track model state before or after saving.

1. isDirty() – Before Saving

Checks if one or more attributes have been modified but not yet saved.

if ($userA->isDirty()) {    // Only save if something was changed

    $user->save();

}

2. wasChanged() – After Saving

Confirms if a model attribute was actually changed during the last save.

$user->name = ‘John’;$user->save();

if ($user->wasChanged(‘name’)) {

    // Fire notification or log the update

}

  • Useful for triggering side effects only after real changes
  • Works after save() has been called
  • Can check specific fields or multiple at once

3. isClean() – When Nothing Has Changed

Returns true if the model hasn’t been modified since it was loaded.

if ($userB->isClean()) {    // Skip any further logic if no update occurred

}

  • Opposite of isDirty()
  • Ideal for skipping controller logic when no update is needed
  • Helps avoid conditional complexity

Also Read: The Popular Sites Built With Laravel

Practical Examples

These examples show how to check if specific fields in a Laravel model have changed, with both single and multiple attributes.

Check Single Attribute

$product = Product::find(1);$product->price = 199;

 

if ($product->isDirty(‘price’)) {

    $product->save();

}

  • Detects if the price was updated before saving
  • Useful for pricing systems, inventory tools, or product dashboards

Check Multiple Attributes

$profile = Profile::find(3);$profile->bio = ‘Updated bio’;

$profile->location = ‘Texas’;

 

if ($profile->isDirty([‘bio’, ‘location’])) {

    $profile->save();

}

  • Verifies if any of the listed fields were touched
  • Great for partial updates in forms or profile sections

Compare Before and After with wasChanged()

$article = Article::find(7);$article->title = ‘New SEO Strategy’;

$article->save();

 

if ($article->wasChanged(‘title’)) {

    Log::info(‘Article title was updated.’);

}

  • Ideal for audit logs or conditional events
  • Ensures the change actually happened after calling save()

When to Use Which Method?

Each method serves a different point in the model lifecycle before or after saving to keep your logic clean and efficient.

  • Use isDirty() → Before saving, to check if data was modified
  • Use wasChanged() → After saving, to confirm if changes were applied
  • Use isClean() → When you want to skip logic if nothing has changed

Conclusion

Laravel makes it simple to detect model changes with isDirty(), wasChanged() and isClean(), giving you full control before and after save operations.

Using the right method at the right time helps reduce overhead, write cleaner code and handle updates more intelligently across your application.

Related

Laravel Soft delete keeps your data safe by hiding it instead of deleting it. The row stays in your database, just marked with a deleted_at…

10 Feb 2026

In the ever evolving landscape of web development, Laravel, the most popular PHP frameworks has become a top choice for businesses looking to create high…

05 Mar 2026

Laravel has become the go to PHP framework for businesses in the USA, powering everything from SaaS platforms and eCommerce marketplaces to enterprise grade applications.…

05 Mar 2026