laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

hasMany, oneToMany, etc. sync() #2515

Open ahinkle opened 3 years ago

ahinkle commented 3 years ago

Hey there folks, one thing that has been poking at me for years is the inability to use sync on relationship that's not many-to-many.

Example: post has many links link belongs to post

$post->links()->sync($links) // error undefined method sync

So, you have to do something nasty like:

$post->links()->delete();
$post->links()->saveMany($links);

This is useful for situations where you would sync relational data with an API or relevant. I would be happy to spin up a pull request if others would find this useful.

JeroenVanOort commented 3 years ago

I think this would be very useful!