Reputation: 4674
I want to maintain a Log table for every field updation. There are 20-30 field in one page. For each field i have to maintain the log. Which means if someone change some perticular launchDate
or something, I need to keep log for that who made that change and time.
Any suggestion will be helpfull.I didn't find any question related to this in SO that's why i am posting this.
Thanks in advance.
Upvotes: 2
Views: 42
Reputation: 4674
Actually $diff = array_diff( $original , Input::all() );
exactly not returns as i want.
So, I am doing this in this following process::
I am using two table for this, one table ( called pf_account_log_data
AS 1st table ) where all posted data stored in JSON format with account_id column. Another table ( called pf_account_log_field_by_user
AS 2nd table ) for which field is being updated and by whoom, which date.
When someone clicks on SAVE button i am checking in my 1st table that is any submitted data is present for that account_id or not. If present then running a foreach loop and chekcing each value corresponding to current posted data and if not equal to previously posted data then i am saving that key with logged_in user_id, time, previous value, current value to 2nd table.
Upvotes: 1
Reputation: 15457
Assuming you have a table in your database where you intend to store the log data, the easiest way to capture all the changes is to store the input posted to the page (e.g. Input::all()
) to a column.
If you want to be efficient in what you store, you can do a diff on the original fields vs new / changed fields:
// switch parameters around depending on what data you want to log
$diff = array_diff( $original , Input::all() );
// store $diff to DB, e.g. as JSON
Upvotes: 0