0
When I work with Laravel in a pivot table where we have only the fields user_id
and post_id
we use something similar to $user->posts()->sync([3,4])
and the pivot table will be updated with posts 3 and 4 for the user in question.
If this user before this operation had posts 3,8 and 9, at the end of the operation he will have only posts 3 and 4.
In another project where I don’t use Laravel what would be the equivalent query to this operation with Sync? In other words, it would be something that deleted the post 8 and 9, kept the 3 and inserted the 4.
You can do this in one query?
So, Sync does two delete and Insert operations and if I’m not mistaken select to see the existing items. Summarizing there is no way to do in an SQL
– novic
Enable the debug on the Laravel to get the sql logs that you can get the exact query.
– Kayo Bruno