Browse Source

Merge pull request #888 from TommyC81/patch-3

Documentation on how to attach data to pivot table
Taylor Otwell 12 years ago
parent
commit
f338db50db
1 changed files with 4 additions and 0 deletions
  1. 4 0
      laravel/documentation/database/eloquent.md

+ 4 - 0
laravel/documentation/database/eloquent.md

@@ -318,6 +318,10 @@ However, you may often only want to insert a new record into the intermediate ta
 
 
 	$user->roles()->attach($role_id);
 	$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>
 <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.
 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.