Answer the question
In order to leave comments, you need to log in
How to perform an action only after updating a specific attribute?
In Yii2 ActiveRecord in EVENT_AFTER_UPDATE I need to perform a certain action, but only when one particular attribute changes. In addition, I need to know the previous value of this attribute. How can this be done?
Answer the question
In order to leave comments, you need to log in
This can be tracked in afterSave. To do this, there is $changedAttributes and the getOldAttribute method.
!$insert && $changedAttributes['name'] !== null && $changedAttributes['name'] !== $this->getOldAttribute('name') - this can be thought of as changing the "name" attribute.
You can also look towards AttributeBehavior.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question