如何在laravel中使用attach方法使用关系

users

id int(10)
name varchar(255)
p_id int(10)

some_record
id int(10)
text varchar(35)


record_relation
some_record_id int(10)
user_id int (10)
or_id int(10)
dr_id int(10)

Relationship using attach method to be clear wanted their store some_record data inside record_relation. How this is possible please guide

Inside some_record model

public function RecordRelation() {
        return $this->belongsToMany('App\Record', 'pivot_table');
    }

Check out this documentation pages: Working with Pivot tables and Inserting related models

To save data in pivot table:

From documentation:

$user->roles()->attach($id, ['expires' => $expires]);

Which in your case would become something like the following:

$user->pivot_table()->attach($some_record_id, ['or_id' => 123, 'dr_id' => 456]);

To update pivot:

From documentation:

User::find(1)->roles()->updateExistingPivot($roleId, $attributes);

Which in your case would become something like the following:

$user->pivot_table()->updateExistingPivot($some_record_id, ['or_id' => 888, 'dr_id' => 999]);

Hope that helps.