Answer the question
In order to leave comments, you need to log in
How to implement monitoring of model field changes if update is done?
There is such a problem. You need to keep track of all changes in the model. The Observer worked well, but it stopped working when they started updating the model in batches - they introduced group processing. For example, a manager, through the admin panel, has selected all several thousand products of a certain supplier and launched a script that will fill in the common field for all of them.
this would be
Items::where('president_id', $president_id)->update(['description => $description]);
How in this case to cleverly fix the changes if the Observers are not working?
The only thing that comes to mind is to Serialize the sample data before and after, and then start the queue for comparison and logging.
Answer the question
In order to leave comments, you need to log in
There is also a standard mechanism of events divided ....
eloquent#events
Handler in the queue, we check whether the field has changed in it, if it has changed, then the handler is launched; if not, it ignores job.
For mass update events are not emitted. Therefore, the Observer stopped working.
It will be much easier than to fence serialization to replace "mass update in one request" with a cycle where you will update each model one by one. After that, the Observer will work again as before.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question