Caio Kawasaki
Caio Kawasaki

Reputation: 2950

Laravel - Keep watching Table Column

I am creating an application and when the user registers the value 0 is assigned to the role column, however as it will using the application, this value can be changed. Is there any method of watching the change of that column? I would like to send an email to the user if this value change to 1.

Upvotes: 1

Views: 125

Answers (1)

I see two possible ways.

1 Use a ModelObserver.

Using a ModelObserver you can "listen" to the saving or updating events. They are called before the action is executed and you can send or queue an e-mail from that method.

Model Observer documentation

2 Use a mutator

You can use a function who will intercept a change in a model property.

Mutators documentation

I hope it helps.

Upvotes: 2

Related Questions