laravel on update check if value change code example

Example 1: check if value change laravel

If you want to check if the model is dirty just call isDirty():

if($product->isDirty()){
    // changes have been made
}
Or if you want to check a certain attribute:

if($product->isDirty('price')){
    // price has changed
}

refrence: https://stackoverflow.com/questions/28866500/laravel-eloquent-update-just-if-changes-have-been-made

Example 2: check if value change laravel

You can use "$product->getChanges()" on Eloquent model even after persisting.

Tags:

Php Example