Skip to content

Commit 6255f72

Browse files
committed
How to insert information into the intermediate table using eloquent.
1 parent 52f2b2b commit 6255f72

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

database/eloquent.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ However, you may often only want to insert a new record into the intermediate ta
303303

304304
$user->roles()->attach($role_id);
305305

306+
If you ever find yourself wanting to add additional data into the intermediate table during an **insert** or **attach** you can do so very easily by passing an array of data as the second parameter for both:
307+
308+
$post->comments()->insert($comment, array('visible' => 1));
309+
310+
$user->roles()->attach($role_id, array('active' => 1));
311+
306312
<a name="intermediate-tables"></a>
307313
## Working With Intermediate Tables
308314

0 commit comments

Comments
 (0)