Anastasie Laurent
Anastasie Laurent

Reputation: 915

laravel many to many delete and update

I have many to many relationship .

in the blade code i sent many items with actionID[]

and then i insert them like this:

$detailsAttribute->actions()->sync(Input::get('action_id'));

now I want to update that model.

i used this same statement

$detailsAttribute->actions()->sync(Input::get('action_id'));

it creates the new actions but didn't remove the older ones. In other words, when I edit the model $detailsAttribute, I delete the older actions and I select many new ones.

my question is how to update the model considering removing the non selected actions?

Upvotes: 1

Views: 551

Answers (1)

Sher Afgan
Sher Afgan

Reputation: 1234

sync() method will remove all those items from pivot table if they are not present in your Input::get('action_id') array. If they are not removed that means you are also passing old data in the new array. var_dump your Input and see what kind of array you are getting.

Upvotes: 1

Related Questions