Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Laravel tracking what was changed.

Posted on 2016-08-17
3
Medium Priority
?
128 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

916 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