1

我的视图中有两个字段,但是要保存的是我的问题,这两个带有 Pivot 的字段具有相同的模型

$this->crud->addField([
    // 1-n relationship
    'label' => "Contacts Business", // Table column heading
    'type' => "contacts",
    'name' => 'contactsbusiness', // Column that contains the ID of that connected entity;
    'entity' => 'contactsbusiness', // Method that defines the relationship in your Model
    'attribute' => "name", // Foreign key attribute that is shown to user
    'idcontact' => '1',
    'model' => "App\Models\Contact", // Foreign key model
    'pivot' => true,
]);

$this->crud->addField([
    // 1-n relationship
    'label' => "Contacts IS+T", // Table column heading
    'type' => "contacts",
    'name' => 'contactsist', // Column that contains the ID of that connected entity;
    'entity' => 'contactsist', // Method that defines the relationship in your Model
    'attribute' => "name", // Foreign key attribute that is shown to user
    'idcontact' => '2',
    'model' => "App\Models\Contact", // Foreign key model
    'pivot' => true,
]);

所以保存时,我的表中只保存了最后一个字段

这是我的关系

public function contactsbusiness()
{
    return $this->belongsToMany('App\Models\Contact','applications_contacts')
    ->withPivot('application_id','contact_id')
    ->where('type_contact_id', 1)
    ->using(ContactPivot::class);
}

public function contactsist()
{
    return $this->belongsToMany('App\Models\Contact','applications_contacts')
    ->withPivot('application_id','contact_id')
    ->where('type_contact_id', 2)
    ->using(ContactPivot::class);
}

欢迎您的帮助!!!

4

0 回答 0