Skip to content

Commit 2043e08

Browse files
authored
Update README.md (#6)
1 parent ce2312a commit 2043e08

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ dump($post->featuredImage);
8585
// lazy loading
8686
$post->load('featuredImage');
8787
```
88+
Prefer using `sync` instead of `save` when updating your relation.
89+
```php
90+
$post->featuredImage()->sync([FeaturedImage::find(123)]);
91+
$post->featuredImage()->sync([FeaturedImage::find(456)]);
92+
$post->images->count(); // 1 row :)
93+
```
94+
95+
:x: DO NOT use `save` it will follow `morphToMany` behaviour and create a new row instead of updating an existing one.
96+
```php
97+
$post->featuredImage()->save(FeaturedImage::find(123));
98+
$post->featuredImage()->save(FeaturedImage::find(456));
99+
$post->images->count(); // 2 rows :(
100+
```
88101

89102
## Testing
90103

0 commit comments

Comments
 (0)