Add documentation on how to attach pivot table fields to attach command.
This commit is contained in:
parent
3ba5c00e5f
commit
f77b22eb45
|
@ -318,6 +318,10 @@ ### Inserting Related Models (Many-To-Many)
|
|||
|
||||
$user->roles()->attach($role_id);
|
||||
|
||||
It's also possible to attach data for fields in the intermediate table (pivot table), to do this add a second array variable to the attach command containing the data you want to attach:
|
||||
|
||||
$user->roles()->attach($role_id, array('expires' => $expires));
|
||||
|
||||
<a name="sync-method"></a>
|
||||
Alternatively, you can use the `sync` method, which accepts an array of IDs to "sync" with the intermediate table. After this operation is complete, only the IDs in the array will be on the intermediate table.
|
||||
|
||||
|
|
Loading…
Reference in New Issue