Suppose I have an
User, and a
Transaction model on Laravel. It doesn't matter the properties, they only have in common an
uuid and a
Now I want to create an
Audit model which will take more or less the following fields:
id - The regular autoincrement id ts - The timestamp when the action is performed actor - The one who performs an action, its a reference to a user's id verb - Which action is performing over a certain object object - The object to which the action is performed comment - whatever
1, 1/1/2021 00:00:01, 1, 'create', User, 'bla bla bla' 2, 1/1/2021 00:00:02, 1, 'update', User, 'reset password'
But that will also apply to other kind of records like the
Transaction I mentioned before
The best way to store an object like that in a database is in a normal form.
I'd suggest creating a new migration and model for your audit, and storing all the relevant information there.
However, you can serialize your object as a string if you don't have any performance concerns, or if the data structure is likely to change. A popular way of doing this is to use