John Priestakos John Priestakos - 3 months ago 14
MySQL Question

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

I'm trying to copy a row from a table to another table with Laravel Query and I get the following error.

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


I've used
CREATE TABLE mod_myinvoices LIKE tblinvoices
to create
mod_myinvoices
table.

Any suggestions ?

Answer

Try it!

Change

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

To

    $invoice = Capsule::table('invoices')->where('id', $invoiceid)->first(); 
    $copiedInvoiceid = Capsule::table('myinvoices')->insertGetId((array)$invoice);
Comments