Home > Back-end >  How to get the edit history of a product on ecommerce website using Laravel, PHP and MYSQL
How to get the edit history of a product on ecommerce website using Laravel, PHP and MYSQL

Time:01-25

I have built an ecommerce website where the admin can edit the products through mysql. Now I want to display the edit history of each product. The edit history should contain the 'date when it was updated' and 'what was updated'.

This is my product table : Click here to see the table

One solution : I thought of creating new columns "Edit history" and "Edit Date" inside the product table. Whenever the admin would edit one column, it would get added here. If anyone knows how to proceed with either this method or some alternative method to solve this issue, please comment down. Thanks.

CodePudding user response:

I would create another table that keeps track of the history, product_history with columns (id, product_id, from (json), to (json), created_at, updated_at).

In the from and to columns just encode the complete content of the old and new row, you could / should do this in a observer.

CodePudding user response:

You could create a Trigger in SQL which would allow that if there is a modification you add automatically in your table the data. I let you look at this course if you want : Sql trigger or Sql Trigger. Then you add for the date a Now for the date of the update (the same day) and for the modifications in your trigger add some SQL to see the difference between the before and after. Also, as mentioned above, creating an Audit table would allow you to save your changes. Your triggers would make it easier to add rows. Good luck to you

CodePudding user response:

one of solutions is use this in products table:

$table->text('history');

when you update the product take the id and store in history the current date and the data like this

{"date":"day-month-year","data":"some data updated bla bla.."}

when you update this put another object in same row of product_id

  •  Tags:  
  • Related