将64个机器人/新星场的BelongsTo字段保存到数据透视表中

时间:2019-04-04 14:28:15

标签: laravel laravel-nova

我正在使用行字段,因此用户可以根据需要创建新行以输入设备。我假设我需要将此数据存储在数据透视表中,但是由于nova-fields不支持多对多字段类型,我该如何实现?

Invoice.php Nova资源:

Row::make('Commodity', [
              BelongsTo::make('Equipment')
                ->searchable()->nullable(),
              RowText::make('ID #', 'serial_numbers')
                ->fieldClasses('w-full px-8 py-6')
                ->hideLabelInForms(),
              RowNumber::make('Quantity')
                ->fieldClasses('w-full px-8 py-6')
                ->hideLabelInForms()
            ]),

2019_04_03_131534_create_equipment_invoice_table:

$table->bigIncrements('id');
        $table->integer('equipment_id')->unsigned();
        $table->integer('invoice_id')->unsigned();
        $table->string('serial_numbers');
        $table->integer('quantity');
        $table->timestamps();

Invoice.php模型和Equipment.php模型:

public function equipment()
        {
           return $this->belongsTo(Equipment::class);
        }

public function invoices()
       {
          return $this->hasMany(Invoice::class);
       }

0 个答案:

没有答案