From 45f22e756165657647b8ce5e3e79109fc75f6566 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 25 Apr 2023 21:31:23 -0700 Subject: [PATCH] Updated the sync to disassociate if all boxed are unchecked Signed-off-by: snipe --- app/Http/Controllers/CustomFieldsController.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 7dbc534e39..9baf42b93b 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -121,8 +121,11 @@ class CustomFieldsController extends Controller if ($field->save()) { // Sync fields with fieldsets - if ($request->has('associate_fieldsets') && (count($request->get('associate_fieldsets')) > 0)) { - $field->fieldset()->sync(array_keys($request->get('associate_fieldsets'))); + $fieldset_array = $request->input('associate_fieldsets'); + if ($request->has('associate_fieldsets') && (is_array($fieldset_array))) { + $field->fieldset()->sync(array_keys($fieldset_array)); + } else { + $field->fieldset()->sync([]); } @@ -273,8 +276,16 @@ class CustomFieldsController extends Controller } if ($field->save()) { + + // Sync fields with fieldsets - $field->fieldset()->sync(array_keys($request->get('associate_fieldsets'))); + $fieldset_array = $request->input('associate_fieldsets'); + if ($request->has('associate_fieldsets') && (is_array($fieldset_array))) { + $field->fieldset()->sync(array_keys($fieldset_array)); + } else { + $field->fieldset()->sync([]); + } + return redirect()->route('fields.index')->with('success', trans('admin/custom_fields/message.field.update.success')); }