Issue
I have a table structure like this :
subscribers with attributes: id, status
I want to have a way to check for the column status : If the status change to 'unsubscribed' then i want to auto detect thats change and apply do something with that.
The workflow is like this :
Anywhere in the code call $subscriber->status = 'unsubscribed'; I want to detect that and do something with that.
Thanks for reading.
I had use isDirty of laravel but that had to write after every $subscriber->status = 'unsubscribed'; so its did not do the work.
Solution
Add the following code to your model:
protected static function booted()
{
static::updated(function (Subscriber $subscriber) {
if ($subscriber->wasChanged('status')) {
// Execute your code
}
});
}
Alternatively, you can use an Observer.
Answered By - Jonas Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.