I am trying to copy all data from one row to another already existing row and change some values.
For example
if the user wants to update row#1, all updates are saved in addition it creates a new row with the current date and new id like row#2.
$updatedEmp = $emp->replicate();
if the user wants to update the same row#1 again, all changes are saved but this time row#2 does already exist. I want to copy all changes from row#1 to row#2 but with the same id of row#2. I've tried to use replicate() function, but it creates a new row and I get an error duplicate for primary key.
I've tried to change the id, but it did not work
if($query){ //not empty
$updatedEmp = $emp->replicate();
$updatedEmp->id = $query->id;
$query = $updatedEmp;
$query->save();
}
I don't have problems with step 1 but step 2 is not working for me. How can I make laravel to update the row instead of inserting a new one?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…