在相同模型的背包Laravel的两个领域

时间:2017-08-07 15:15:35

标签: laravel backpack-for-laravel

我的视图中有两个字段,但保存是我的问题这两个字段白色字体有相同的模型

$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);
}




欢迎您的帮助!!!

0 个答案:

没有答案