Solved

Laravel tracking what was changed.

Posted on 2016-08-17
3
79 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysqli insert query problems 4 22
error log using ftp 7 41
Curl & PHP Command Help 4 23
How do I fix this UPDATE error? 7 23
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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