From f77b22eb45af6fbdd37078feda09776c96b9ca41 Mon Sep 17 00:00:00 2001 From: TommyC81 Date: Sat, 30 Jun 2012 18:11:31 +0300 Subject: [PATCH] Add documentation on how to attach pivot table fields to attach command. --- laravel/documentation/database/eloquent.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/laravel/documentation/database/eloquent.md b/laravel/documentation/database/eloquent.md index c2afc7a2..5858224b 100644 --- a/laravel/documentation/database/eloquent.md +++ b/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); +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)); + 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.