1

ビュー内に 2 つのフィールドがありますが、保存することが私の問題です。この 2 つのフィールドのピボットには同じモデルがあります。

$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