Move one table data into another table in Laravel

In this tutorial, I will explain to you how to move one data into another data.

In this tutorial, I will explain Laravel has an inbuilt method replicate() to use in the model to move one table to another table.

Here is some basic code of replicate method:

Customer::query()
  ->each(function ($oldcustomer) {
    $newcustomer = $oldcustomer->replicate();
    $newcustomer->setTable('old_customers');
    $newcustomer->save();
    $oldcustomer->delete();
  });

I hope it will help you with some cases in laravel for moving data from one table to another.

About Dhaval Shah

My name is Dhaval Shah. I'm a Laravel developer. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress, and Bootstrap.
Follow me on Github / Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!