public function destroy(CustomField $custom_field)
 {
     if (!Entrust::can('manage_custom_field')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Helper::getMode()) {
         return redirect()->back()->withErrors(config('constants.DISABLE_MESSAGE'));
     }
     $custom_field->delete();
     $activity = 'Deleted a Custome Field';
     Activity::log($activity);
     return redirect('/custom_field')->withSuccess(config('constants.DELETED'));
 }
Example #2
0
 /**
  *  Remove a custom field from the outline and delete it
  *
  *  @param   int  $outlineId  Outline ID
  *  @param   int  $customId   CustomField ID
  *
  *  @return  Response    A JSON encoded result message
  */
 public function getOutlineRemoveCustom($outlineId, $customId)
 {
     if (!$outlineId || !$customId) {
         return response()->json(['message', 'Some ID was empty'], 404);
     }
     try {
         $field = CustomField::findOrFail($customId);
     } catch (ModelNotFoundException $e) {
         return response()->json(['message', 'No such custom field'], 404);
     }
     $field->delete();
     return response()->json(['message', 'Removed custom field from outliner'], 200);
 }
Example #3
0
 public static function updateCustomField($form, $id, $request)
 {
     $custom_fields = CustomField::whereForm($form)->get();
     foreach ($custom_fields as $custom_field) {
         $value = array_key_exists($custom_field->field_name, $request) ? $request[$custom_field->field_name] : '';
         $custom = DB::table('custom_fields')->join('custom_field_values', 'custom_field_values.field_id', '=', 'custom_fields.id')->where('form', '=', $form)->where('field_name', '=', $custom_field->field_name)->where('unique_id', '=', $id)->select(DB::raw('custom_field_values.id'))->first();
         if ($custom) {
             $custom_field_value = CustomFieldValue::find($custom->id);
         } else {
             $custom_field_value = new CustomFieldValue();
         }
         $custom_field_value->value = $value;
         $custom_field_value->field_id = $custom_field->id;
         $custom_field_value->unique_id = $id;
         $custom_field_value->save();
     }
 }