Solved

Laravel tracking what was changed.

Posted on 2016-08-17
3
113 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

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 110

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

734 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