how to save only selected items using hasMany on update and remove already save items not selected.
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.
I had the same question/problem. I sloved it by creating extra hidden input for each delete button click and saved ID of deleted value into that hidden input (name: deleted_fields[]). So in controller I just deleted all fields from deleted_fields array and updated what left :)