1If you want to check if the model is dirty just call isDirty():
2
3if($product->isDirty()){
4 // changes have been made
5}
6Or if you want to check a certain attribute:
7
8if($product->isDirty('price')){
9 // price has changed
10}
11
12refrence: https://stackoverflow.com/questions/28866500/laravel-eloquent-update-just-if-changes-have-been-made
1class UserObserver
2{
3
4
5 /**
6 * Listen to the User created event.
7 *
8 * @param \App\User $user
9 * @return void
10 */
11 public function updating(User $user)
12 {
13 if($user->isDirty('email')){
14 // email has changed
15 $new_email = $user->email;
16 $old_email = $user->getOriginal('email');
17 }
18 }
19
20}
21
1protected function performUpdate(Builder $query, array $options = [])
2{
3 $dirty = $this->getDirty();
4
5 if (count($dirty) > 0)
6 {
7 // runs update query
8 }
9
10 return true;
11}