首页 > 解决方案 > 无法使用 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、数量、单位、净单位、净总、增值税率、总单位、总总

标签: phpsqllaraveleloquentorm

解决方案


推荐阅读