1

I have mulutiselect option enabled in select html code, my frontend look like this: enter image description here

For example if user unselect some option and select other how can I update it in database, any idea?

halfer
  • 19,824
  • 17
  • 99
  • 186
Vladimir Djukic
  • 2,042
  • 7
  • 29
  • 60

1 Answers1

1

If you have ManyToMany relationships between say Group and Project you can use sync() method to maintain association as below,

$group->projects()->sync([$projId1, $projId2]);

Above will remove all previous association between current group($group) and projects and associates newly supplied projects i.e. $projId1, $projId2.

If you want to maintain previous associations pass false as a second argument in sync() as below,

$group->projects()->sync([$projId1, $projId2], false);

Above code will maintain previous Group and Project association and will also associate passed projects.

pinkal vansia
  • 10,240
  • 5
  • 49
  • 62