Skip to content

Commit 020d4cb

Browse files
committed
Updating docs with associate method.
1 parent 69ba91a commit 020d4cb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

eloquent.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,16 @@ You will often need to insert new related models. For example, you may wish to i
621621

622622
In this example, the `post_id` field will automatically be set on the inserted comment.
623623

624+
### Associating Models (Belongs To)
625+
626+
When updating a `belongsTo` relationship, you may use the `associate` method. This method will set the foreign key on the child model:
627+
628+
$account = Account::find(10);
629+
630+
$user->associate($account);
631+
632+
$user->save();
633+
624634
### Inserting Related Models (Many To Many)
625635

626636
You may also insert related models when working with many-to-many relations. Let's continue using our `User` and `Role` models as examples. We can easily attach new roles to a user using the `attach` method:

0 commit comments

Comments
 (0)