We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce2312a commit 2043e08Copy full SHA for 2043e08
README.md
@@ -85,6 +85,19 @@ dump($post->featuredImage);
85
// lazy loading
86
$post->load('featuredImage');
87
```
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
97
+$post->featuredImage()->save(FeaturedImage::find(123));
98
+$post->featuredImage()->save(FeaturedImage::find(456));
99
+$post->images->count(); // 2 rows :(
100
101
102
## Testing
103
0 commit comments