我尝试使用Laravel Query将一行从一个表复制到另一个表,我收到以下错误。
$invoice = Capsule::table('tblinvoices')->where('id', $invoiceid)->get(); //array
$copiedInvoiceid = Capsule::table('mod_myinvoices')->insertGetId(array($invoice));
错误:SQLSTATE [42S22]:找不到列:1054未知列' 0'在'字段列表' (SQL :)
我已使用CREATE TABLE mod_myinvoices LIKE tblinvoices
创建mod_myinvoices
表。
有什么建议吗?
答案 0 :(得分:1)
试试吧!
更改强>
$invoice = Capsule::table('invoices')->where('id', $invoiceid)->get();
$copiedInvoiceid = Capsule::table('myinvoices')->insertGetId(array($invoice));
要强>
$invoice = Capsule::table('invoices')->where('id', $invoiceid)->first();
$copiedInvoiceid = Capsule::table('myinvoices')->insertGetId((array)$invoice);
答案 1 :(得分:0)
试试吧。
$invoice = Capsule::table('invoices')->where('id', $invoiceid)->get();
$invoiceArr = (array) $invoice[0]; // convert object to array
$copiedInvoiceid = Capsule::table('myinvoices')->insertGetId($invoiceArr);