demonz's avatar

replace the entire db row with other row

hello i have two tables in php laravel having the same columns , i want to replace a row in table 1 with a row in table 2 , can we do it in one step without equal all the columns

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, you can replace a row in table 1 with a row in table 2 using Laravel's query builder. Here's an example:

DB::table('table1')->where('id', $id)->update(
    DB::table('table2')->where('id', $id)->first()
);

This code will update the row in table1 with the same id as the $id variable with the values from the row in table2 with the same id. Note that this assumes that both tables have the same column names and data types. If they don't, you'll need to map the columns manually.

1 like

Please or to participate in this conversation.