亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

方法 Illuminate\Database\Eloquent\Collection::create

方法 Illuminate\Database\Eloquent\Collection::create

PHP
手掌心 2023-09-08 16:58:09
我想使用視圖中的按鈕將一個表(形式)中的行的值復制到另一個表(發票)中的行。但出現錯誤:方法 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條經驗 獲得超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 是發票模型實例的集合。您不能create對集合應用方法。


您需要使用您擁有的模型進行創建Invoice。


所以將上面的創建代碼修改為


$duplicated = Invoice::create([..


查看完整回答
反對 回復 2023-09-08
  • 1 回答
  • 0 關注
  • 139 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號