Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

riliwanrabo's avatar

How to make a data persist temporarily until approved by an Admin

Hi great minds!

I am building an HR software and I will like to implement a special feature which is as below :-

~> When an ordinary employee/staff updates his information, I would like it to persist maybe in a temporary table,

~> Notify the admin of the changes,

~> Admin decides to approve or rejects the change and the user gets a notification of that effect.

What I had thought I would do

~> Create a Temporary table (Like a duplicate of the real table(employees) )

~> When the employee make changes, it saves on this table not the real table,

~> The admin/HR gets notification of the changes made

~> He approves/Reject, and that record on this table initiated by that ordinary employee is deleted if rejected but transferred to the main table if approved.

-- I haven't tried my imagined solution yet but I know great minds such as yours might have better way or perhaps a package that does an integral part of this

cheers

0 likes
10 replies
Jaytee's avatar

Alternatively, use 1 table. Have a column on table such as: approved that takes a boolean value. If the value is 1, then it's approved, in that case, notify the user.

If value is 0, then it's declined, remove the row from the table.

EDIT: I didn't think that through entirely. I'd use what you've listed.

martinbean's avatar

@riliwanrabo You don’t want to ‘duplicate’ your tables, as that means you have to duplicate every table you want to add peer-reviewing to.

Instead, consider storing “revisions” of rows. Each user has multiple rows. Every time they change something, a new row is created but has a column and value of say, approved = 0. Managers can set approved to 1 to approve the change. So to get the user’s latest profile, you just select the last record with approved = 1.

SteveBelanger's avatar

I use to think that way too, but after asking such question on dba stackexchange (http://dba.stackexchange.com/), I changed my architecture a bit. I would rather not make a duplicate table, but add a tinyint* field to the table, named adminApproved , Official or something like that.
When an employee would propose a change, a row would be added with that tinyint field at 0 (false) When an admin would approve it the field would be put from 0 (false) to 1 (true) , and the old row turned to 0 When an admin would reject, the row could be deleted.

you would have add this to your queries : ->where('adminApproved', '=', '1')

It seems like your table would get "messy", but this is apparently better than duplicating tables and "copy/pasitng" rows from one to the other.

good luck !

*Laravel seems to use tinyint when we want a boolean.

riliwanrabo's avatar

@Prez seems to answer what i requested.

Here is part of the scenerio:- @DPJack , @martinbean , @SteveBelanger

~> I am an admin and @Prez id my employee

~> @Prez decide to update his first_name, last_name, mid_name and email columns.

~> Those changes would be stored temporarily

~> After I get a notification of those changes I decide to approve or reject i.e revert or keep those changes respectively.

For now I go with @Prez who said i should have a column where I store those changed column as JSON, use the data to update when I approve then nullify or just nullify when I reject.

@Prez Hope I understood your suggestions.

@DPJack , @martinbean , @SteveBelanger Do you agree ?

cheers

1 like
spekkionu's avatar

I implemented basically this same functionality many years ago in basically the exact way you describe with a second table that was basically a copy of the original. When changes were approved I copied the data over to the original and if they were declined I would delete the pending data.

This turned out to most definitely be the wrong way of doing it and made that project a huge pain to work with and is the source of a seemingly never ending supply of bugs even to this day.

The method Prez describes sound much better and is what I would do if I had to build the same project again today. Hopefully this saves you some of the pain I've had to go through.

1 like
riliwanrabo's avatar

@spekkionu YeahI agree with @Prez I haven't implemented his suggestion yet but oh my it makes a whole lot of sense. As soon as I apply it i tick it as the right answer

jekinney's avatar

Jeffery did a video few months ago about this. Laravel has some built it features that makes it quite easy. That way your only storing some of the data, just what's been changed, in a Json object so it's ver dynamic and can be implemented as polymorphic for many tables later if needed.

https://laracasts.com/series/eloquent-techniques/episodes/2

2 likes

Please or to participate in this conversation.