How can i copy a record and save it with a different value for 1 or more field?
for example: get----> first_name, last_name, civil_status, work
i want to copy the first name, and last name then insert it with a new civil status and work.
We will follow the below steps: Create a new instance with replicate() method based on the old or original record. Store this new instance with save() method and setTable() method in the new table. Delete the old record from the original table with delete() method of a model.
Using insertOrIgnore we can easily remove duplicate content. So now see how to avoid duplicate entry in database in laravel application. So we will insert data laravel insert if not exists. We will ignore duplicate records while inserting records into DB table in laravel application using insertOrIgnore.
You could use the replicate
method of model like this:
// Retrieve the first task $task = Task::first(); $newTask = $task->replicate(); $newTask->project_id = 16; // the new project_id $newTask->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With