/** * @Route("/ajax", methods="POST") * @Request({"field_id": "int", "action": "string"}) */ public function ajaxAction($field_id, $action) { if (!($field = Field::find($field_id))) { App::abort(400, __('Field not found.')); } $fieldValue = new FieldValue($field, App::request()->get('value', []), App::request()->get('valuedata', [])); $fieldType = $fieldValue->getFieldType(); if (method_exists($fieldType, $action)) { return call_user_func([$fieldType, $action], $fieldValue); } return 'No response'; }
/** * @Route("/{id}", methods="DELETE", requirements={"id"="\d+"}) * @Request({"id": "int"}, csrf=true) */ public function deleteAction($id) { if ($field = Field::find($id)) { $field->delete(); } return ['message' => 'success']; }