php - 无法使用 Laravel Eloquent 将所有数据从一个表发送到另一个表
问题描述
开具发票按钮是将表格中的一行发送到发票。大多数列具有相同的名称。还有一个问题,因为一半的价值没有转移。我在 dd($proform) 上调用 $proform,它就在那里。我究竟做错了什么?在这里你可以看到我是如何检查总单位的,数值显示得很好,但没有发送到第二个表。这是我的控制器的一部分。
public function duplicate(Request $request)
{
$proform = $this->proform->findOrFail($request->duplicate);
$invoice = Invoice::all();
dd($proform->grossunit);
//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]);
}
这是发票模型:
<?php
namespace App;
use Kyslik\ColumnSortable\Sortable;
use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
use Sortable;
protected $fillable = [
'invoicenumber', 'invoicedate', 'id', 'selldate', 'user_id', 'paymentmethod',
'paymentdate', 'status', 'comments', 'city', 'paid', 'autonumber', 'automonth', 'autoyear', 'name',
'PKWIU', 'quantity', 'unit', 'netunit', 'nettotal',
'VATrate', 'grossunit', 'grosstotal', 'form_id', 'currency_id',
];
public $sortable = [ 'invoicenumber', 'invoicedate', 'id', 'selldate',
'user_id', 'paymentmethod', 'paymentdate', 'status', 'comments', 'grosstotal', 'nettotal', 'form_id', 'currency_id',];
public function user()
{
return $this->belongsTo('App\User');
}
public function form()
{
return $this->hasOne('App\Form');
}
public function currency()
{
return $this->hasOne('App\Currency');
}
public function proform()
{
return $this->belongsTo('App\Proform');
}
}
此字段不成立:名称、PKWIU、数量、单位、净单位、净总、增值税率、总单位、总总
解决方案
推荐阅读
- c - 如何确定使用C语言在终端中输入的参数的值
- python - 无法在 Kivy (Python) 中禁用按钮
- go - 上传到互联网站点
- qt - 为什么将文档打印到 PDF 会崩溃?
- r - 在R中计算2次之间的营业时间
- qt - 如何避免 QStackedLayout 中包含隐藏的 QWidget 高度?
- javascript - 如何将 node.js 用于离线应用程序
- api - 我想从 RestAssured 的响应中断言“Total”,有人可以建议我如何做到这一点
- android - Compose ConstraintLayout 是否为 INVISIBLE 和 GONE 提供与基于视图的 ConstraintLayout 相同的处理?
- python - Python/Gunicorn ssl 握手失败