我想使用視圖中的按鈕將一個表(形式)中的行的值復制到另一個表(發(fā)票)中的行。但出現(xiàn)錯誤:方法 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]);}
1 回答

當年話下
TA貢獻1890條經(jīng)驗 獲得超9個贊
在你的代碼中你有
// all() gets you the collection of the Invoice Model instances of all the entries of invoice in the database.
$invoice = Invoice::all();
$duplicated = $invoice->create([..
其中 $invoice 是發(fā)票模型實例的集合。您不能create對集合應用方法。
您需要使用您擁有的模型進行創(chuàng)建Invoice。
所以將上面的創(chuàng)建代碼修改為
$duplicated = Invoice::create([..
- 1 回答
- 0 關注
- 124 瀏覽
添加回答
舉報
0/150
提交
取消