Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: )

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: )

我正在尝试使用 Laravel 查询将行从 table 复制到另一个 table,但出现以下错误。

$invoice = Capsule::table('tblinvoices')->where('id', $invoiceid)->get(); //array
$copiedInvoiceid = Capsule::table('mod_myinvoices')->insertGetId(array($invoice));

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: )

我用 CREATE TABLE mod_myinvoices LIKE tblinvoices 创建了 mod_myinvoices table。

有什么建议吗?

试试吧!

改变

    $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);

试试吧。

$invoice = Capsule::table('invoices')->where('id', $invoiceid)->get();

$invoiceArr = (array) $invoice[0]; // convert object to array    

$copiedInvoiceid = Capsule::table('myinvoices')->insertGetId($invoiceArr);