how to save only selected items using hasMany on update and remove already save items not selected.

Posted 2 years ago by umefarooq

Hi, i need help for updating one to many relationship, i am using multiple select dropdwon list and checkbox array to save information. first time save is working fine, on update if i uncheck or not selecting any old item, it should save only selected items, already save uncheck or not selected item should be deleted from database.

it is one to many relation not many to many relation. I am try to save time slots for a user in user_times table

$user->times()->saveMany($slot);

$user->times()->delete() works fine for me but its deleting all saved records for user and creates new.

Please sign in or create an account to participate in this conversation.