Solved

Laravel tracking what was changed.

Posted on 2016-08-17
3
85 Views
1 Endorsement
Last Modified: 2016-08-17
I am a simple form with a few field displaying a person's contact information and when they edit it, I send the information out with ajax, is there a way with laravel that I can track what was the original form vs just the new information that is being sent out?
1
Comment
Question by:rivkamak
  • 2
3 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41759586
Great question!  There is a general design pattern used for things like this.  You never replace  a value in the contact information table.  Instead, you just append  the new values to the end of the table by adding a new row.  The result is a historical record of all changes.

When you want the most current value, your query uses something like ORDER BY id  DESC LIMIT 1.

When you want the historical perspective (to track changes) your query uses ORDER BY id  DESC.  This returns a 1-or-more results collection, and you can iterate through it to find the changes.
0
 

Author Comment

by:rivkamak
ID: 41759733
Let's say, I have a phone number
111-111-1111
and the user comes in and change it to
222-222-2222

i want to send a proc out notification to the manager that someone changed their phone number
old number : is ____
new number is  $_POST['number']

is there a way to pull what was there before?
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41759771
Not sure of the best "Laravel way" to do that (active record design should make this easy), but "in the raw" you might use a SELECT query to get the existing number, then use an INSERT query to add the new number from $_POST.  That would give you variables with both the old and new numbers and you can send the notification at that point.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question