Laravel Insert data from one table to another

//Using Eloquent

//Inserting data from one table to another

$data = DB::table(‘table1’)->get();

foreach($data as $row) {
DB::table(‘table2’)->insert([
‘column1’ => $row->column1,
‘column2’ => $row->column2,
‘column3’ => $row->column3
]);
}

//Using Query Builder

$data = DB::table(‘table1’)->get();

foreach($data as $row) {
DB::table(‘table2’)->insert([
‘column1’ => $row->column1,
‘column2’ => $row->column2,
‘column3’ => $row->column3
]);
}

We and our partners use cookies to Store and/or access information on a device. We and our partners use data for Personalised ads and content, ad and content measurement, audience insights and product development. An example of data being processed may be a unique identifier stored in a cookie. Some of our partners may process your data as a part of their legitimate business interest without asking for consent. To view the purposes they believe they have legitimate interest for, or to object to this data processing use the vendor list link below. The consent submitted will only be used for data processing originating from this website. If you would like to change your settings or withdraw consent at any time, the link to do so is in our privacy policy accessible from our home page..

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?