John Priestakos
John Priestakos

Reputation: 390

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 ?

Upvotes: 0

Views: 1245

Answers (2)

harpreet singh
harpreet singh

Reputation: 1

Try it.

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

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

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

Upvotes: 0

KmasterYC
KmasterYC

Reputation: 2354

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

Upvotes: 1

Related Questions