Answer the question
In order to leave comments, you need to log in
How to copy rows from one table to another?
How it is better to make such rewriting from one table in another?
There are 2 tables:
Wallets:
...| user_id | type | money | ... |
Stats:
..| user_id | currency | money |
$wallets = Wallets::all();
// здесь $wallets нужно сохранить в Stats
Answer the question
In order to leave comments, you need to log in
DB::raw("INSERT INTO Wallets (user_id, type, money)
SELECT user_id, currency, money FROM Stats")
The obvious problem is that your columns in the tables do not match.
In general, your problem can be solved with one query
INSERT INTO table1 (column1) SELECT col1 FROM table2
DB::table('users')->insert([
['email' => '[email protected]', 'votes' => 0],
['email' => '[email protected]', 'votes' => 0]
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question