Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Čamo's avatar
Level 3

How to log model history

I need to log history of entity changes, but including its relations. The first idea was to use events. BUT there is a problem. I can not ensure that whole entity including its relations will be stored when update event triggers. So the question is what is a best practise for something like this. I would like to have history like some properties in the table and whole entity including relations like json in the table.

How to do it if entity->save() is called before relations->sync()?

Thanks for help.

0 likes
7 replies
Čamo's avatar
Level 3

@automica But I do not see any documentation to related enetities. Is it really what I need?

Čamo's avatar
Level 3

Is there a way to do it without any other package?

Čamo's avatar
Level 3

I made a middleware which runs after whole request is done and which have access to new entity with all relations and make history image from it.

Please or to participate in this conversation.