Laravel: How to fire event when a particular column in users table changes?

Viewed 3262

In my users table I have a column with the name verified and data type boolean with default value 'false', However, I want to fire an event when that column value to any particular user changes to 'true', So i can make a notification based on that event? Any ideas how I can achieve this?

3 Answers

You could use the Attribute Events package to fire events when a model attribute changes: https://github.com/jpkleemans/attribute-events

class User extends Model
{
    protected $dispatchesEvents = [
        'verified:true' => UserVerified::class,
    ];
}
Related