Added fieldset sync

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2023-04-25 21:29:57 -07:00
parent 5eeca937cb
commit 15dc4e4779
2 changed files with 28 additions and 5 deletions

View file

@ -94,6 +94,18 @@ class CustomFieldsetsController extends Controller
$fieldset->fill($request->all()); $fieldset->fill($request->all());
if ($fieldset->save()) { if ($fieldset->save()) {
// Sync fieldset with auto_add_to_fieldsets
$fields = CustomField::select('id')->where('auto_add_to_fieldsets', '=', '1')->get();
if ($fields->count() > 0) {
foreach ($fields as $field) {
$field_ids[] = $field->id;
}
$fieldset->fields()->sync($field_ids);
}
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.create.success'))); return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.create.success')));
} }

View file

@ -93,16 +93,27 @@ class CustomFieldsetsController extends Controller
{ {
$this->authorize('create', CustomField::class); $this->authorize('create', CustomField::class);
$cfset = new CustomFieldset([ $fieldset = new CustomFieldset([
'name' => e($request->get('name')), 'name' => e($request->get('name')),
'user_id' => Auth::user()->id, 'user_id' => Auth::user()->id,
]); ]);
$validator = Validator::make($request->all(), $cfset->rules); $validator = Validator::make($request->all(), $fieldset->rules);
if ($validator->passes()) {
$cfset->save();
return redirect()->route('fieldsets.show', [$cfset->id]) if ($validator->passes()) {
$fieldset->save();
// Sync fieldset with auto_add_to_fieldsets
$fields = CustomField::select('id')->where('auto_add_to_fieldsets', '=', '1')->get();
if ($fields->count() > 0) {
foreach ($fields as $field) {
$field_ids[] = $field->id;
}
$fieldset->fields()->sync($field_ids);
}
return redirect()->route('fieldsets.show', [$fieldset->id])
->with('success', trans('admin/custom_fields/message.fieldset.create.success')); ->with('success', trans('admin/custom_fields/message.fieldset.create.success'));
} }