Question: I am using an [Observer](https://laravel.com/docs/5.5/eloquent#observers) to watch if a user was updated.

Whenever a user is `updated` I would like to check if his `email` has been changed. 

Is something like this possible?

```
class UserObserver
{

    /**
     * Listen to the User created event.
     *
     * @param  \App\User  $user
     * @return void
     */
    public function updating(User $user)
    {
      // if($user->hasChangedEmailInThisUpdate()) ?
    }

}

```

Answer: 
Edit: Credits to <https://stackoverflow.com/a/54307753/2311074> for `getOriginal`

As `tadman` already said in the comments, the method `isDirty` does the trick:

```
class UserObserver
{

    /**
     * Listen to the User updating event.
     *
     * @param  \App\User  $user
     * @return void
     */
    public function updating(User $user)
    {
      if($user->isDirty('email')){
        // email has changed
        $new_email = $user->email; 
        $old_email = $user->getOriginal('email');
      }
    }

}

```

If you want to know the difference between `isDirty` and `wasChanged`, see <https://stackoverflow.com/a/49350664/2311074>
Instead of using the `updating` event, You should use the `updated` model event to compare the column changes against the original. Please have a look at the below code.

AppServiceProvider.php

```
<?php

namespace App\Providers;

use App\Models\User;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        User::updated(function($user){
            $changes = array_diff($user->getOriginal(), $user->getAttributes());
            if(array_key_exists('email',$changes)){
                /* do your things. */
            }
        });
    }
}

```

Explanation:

* Once you get the difference then you need to use `array_key_exists` to check whether the email field got updated or not.