我想使用视图中的按钮将一个表(形式)中的行的值复制到另一个表(发票)中的行。但出现错误:方法 Illuminate\Database\Eloquent\Collection::create 不存在。在线的:'grosstotal' => $proform->grosstotal,
这是我的控制器方法:
public function duplicate(Request $request)
{
$proform = $this->proform->findOrFail($request->duplicate);
$invoice = Invoice::all();
//something like this
$duplicated = $invoice->create([
'invoicenumber' => $proform->proformnumber,
'invoicedate' => $proform->proformdate,
'selldate' => $proform->selldate,
'user_id' => $proform->user_id,
'form_id' => $proform->form_id,
'currency_id' => $proform->currency_id,
'paymentmethod' => $proform->paymentmethod,
'paymentdate' => $proform->paymentdate,
'status' => $proform->status,
'comments' => $proform->comments,
'city' => $proform->city,
'autonumber' => $proform->autonumber,
'automonth' => $proform->automonth,
'autoyear' => $proform->autoyear,
'name' => $proform->name,
'PKWIU' => $proform->PKWIU,
'quantity' => $proform->quantity,
'unit' => $proform->unit,
'netunit' => $proform->netunit,
'nettotal' => $proform->nettotal,
'VATrate' => $proform->VATrate,
'grossunit' => $proform->grossunit,
'grosstotal' => $proform->grosstotal,
]);
return redirect()->route('invoices.show', ['invoice' => $duplicated]);
}
当年话下