cbj4074
4 years ago
8738
15
Laravel

How best to copy a row of data from one table to another?

Posted 4 years ago by cbj4074

I have a need to copy a row of data from one database table to another.

What is the best means by which to accomplish this in Laravel?

The question at http://stackoverflow.com/questions/25043944/copying-one-rows-data-to-another-row-with-laravels-eloquent-or-fluent is very similar, but the accepted answer seems to assume that some version of the record already exists in both tables (whereas in my case, the record exists only in the first table).

I found the /Illuminate/Database/Eloquent/Model::setTable() method, and it seems to "work" in that when I inspect the model after calling it, the #table property reflects the new value, but when I call save() on the model, the data is not written to the DB. Yet, the save() call returns true.

Further, I notice that if I pass an invalid/non-existent table name, e.g., setTable('table_does_not_exist'), the call still returns true.

Any assistance in this regard would be much appreciated!

Thanks in advance!

Please sign in or create an account to participate in this conversation.