diff --git a/app/Http/Controllers/CustomFieldsetsController.php b/app/Http/Controllers/CustomFieldsetsController.php index e3e0ddcb90..f8b96e81c7 100644 --- a/app/Http/Controllers/CustomFieldsetsController.php +++ b/app/Http/Controllers/CustomFieldsetsController.php @@ -194,4 +194,44 @@ class CustomFieldsetsController extends Controller } + + /** + * Set the field in a fieldset to required + * + * @author [A. Gianotto] [] + * @since [v5.0] + */ + public function makeFieldRequired($fieldset_id, $field_id) + { + + $this->authorize('update', CustomFieldset::class); + $field = CustomField::findOrFail($field_id); + $fieldset = CustomFieldset::findOrFail($fieldset_id); + $fields[$field->id] = ['required' => 1]; + $fieldset->fields()->syncWithoutDetaching($fields); + + return redirect()->route('fieldsets.show', ['fieldset' => $fieldset_id]) + ->with("success", trans('Field successfully set to required')); + + } + + /** + * Set the field in a fieldset to optional + * + * @author [A. Gianotto] [] + * @since [v5.0] + */ + public function makeFieldOptional($fieldset_id, $field_id) + { + $this->authorize('update', CustomFieldset::class); + $field = CustomField::findOrFail($field_id); + $fieldset = CustomFieldset::findOrFail($fieldset_id); + $fields[$field->id] = ['required' => 0]; + $fieldset->fields()->syncWithoutDetaching($fields); + + return redirect()->route('fieldsets.show', ['fieldset' => $fieldset_id]) + ->with("success", trans('Field successfully set to optional')); + + } + } diff --git a/resources/views/custom_fields/fieldsets/view.blade.php b/resources/views/custom_fields/fieldsets/view.blade.php index f201d90dea..c74360ca2b 100644 --- a/resources/views/custom_fields/fieldsets/view.blade.php +++ b/resources/views/custom_fields/fieldsets/view.blade.php @@ -56,7 +56,19 @@ {{$field->format}} {{$field->element}} {{ $field->field_encrypted=='1' ? trans('general.yes') : trans('general.no') }} - {{$field->pivot->required ? "REQUIRED" : "OPTIONAL"}} + + @if ($field->pivot->required) + + + Required - click to make optional + + @else + + + Optional - click to make required + + @endif + @can('update', $custom_fieldset) Remove diff --git a/routes/web/fields.php b/routes/web/fields.php index 18a403aae1..00815b2d04 100644 --- a/routes/web/fields.php +++ b/routes/web/fields.php @@ -7,6 +7,16 @@ Route::group([ 'prefix' => 'fields','middleware' => ['auth'] ], function () { + Route::get('required/{fieldset_id}/{field_id}', + ['uses' => 'CustomFieldsetsController@makeFieldRequired', + 'as' => 'fields.required'] + ); + + Route::get('optional/{fieldset_id}/{field_id}', + ['uses' => 'CustomFieldsetsController@makeFieldOptional', + 'as' => 'fields.optional'] + ); + Route::get('{field_id}/fieldset/{fieldset_id}/disassociate', ['uses' => 'CustomFieldsController@deleteFieldFromFieldset', 'as' => 'fields.disassociate']