] */ class CustomFieldsController extends Controller { /** * Returns a view with a listing of custom fields. * * @author [Brady Wetherington] [] * @since [v1.8] * @return View */ public function index() { $fieldsets = CustomFieldset::with("fields", "models")->get(); $fields = CustomField::with("fieldset")->get(); return View::make("custom_fields.index")->with("custom_fieldsets", $fieldsets)->with("custom_fields", $fields); } /** * Returns a view with a form to create a new custom field. * * @see CustomFieldsController::storeField() * @author [Brady Wetherington] [] * @since [v1.8] * @return View */ public function create() { return View::make("custom_fields.create_field"); } /** * Validates and stores a new custom field. * * @see CustomFieldsController::createField() * @author [Brady Wetherington] [] * @since [v1.8] * @return Redirect */ public function store(Request $request) { $field = new CustomField([ "name" => e($request->get("name")), "element" => e($request->get("element")), "field_values" => e($request->get("field_values")), "field_encrypted" => e($request->get("field_encrypted", 0)), "user_id" => Auth::user()->id ]); if (!in_array(Input::get('format'), array_keys(CustomField::$PredefinedFormats))) { $field->format = e($request->get("custom_format")); } else { $field->format = e($request->get("format")); } $validator=Validator::make(Input::all(), $field->rules); if ($validator->passes()) { $results = $field->save(); if ($results) { return redirect()->route("fields.index")->with("success", trans('admin/custom_fields/message.field.create.success')); } else { dd($field); return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.field.create.error')); } } else { return redirect()->back()->withInput()->withErrors($validator); } } /** * Detach a custom field from a fieldset. * * @author [A. Gianotto] [] * @since [v3.0] * @return Redirect */ public function deleteFieldFromFieldset($field_id, $fieldset_id) { $field = CustomField::find($field_id); if ($field->fieldset()->detach($fieldset_id)) { return redirect()->route('fieldsets.show', ['fieldset' => $fieldset_id])->with("success", trans('admin/custom_fields/message.field.delete.success')); } return redirect()->back()->withErrors(['message' => "Field is in-use"]); } /** * Delete a custom field. * * @author [Brady Wetherington] [] * @since [v1.8] * @return Redirect */ public function destroy($field_id) { $field = CustomField::find($field_id); if ($field->fieldset->count()>0) { return redirect()->back()->withErrors(['message' => "Field is in-use"]); } else { $field->delete(); return redirect()->route("fields.index")->with("success", trans('admin/custom_fields/message.field.delete.success')); } } /** * What the actual fuck, Brady? * * @todo Uhh, build this? * @author [Brady Wetherington] [] * @param int $id * @since [v1.8] * @return Fuckall */ public function edit($id) { // } /** * GET IN THE SEA BRADY. * * @todo Uhh, build this too? * @author [Brady Wetherington] [] * @param int $id * @since [v1.8] * @return Fuckall */ public function update($id) { // } }