src/Rest/CrudCustomFieldsController.php
public function create(): Response
    {
        $request = $this->request->getPost();

        if (empty($request)) {
            $request = $this->request->getJsonRawBody(true);
        }

        //we need even if empty the custome fields
        if (empty($request)) {
            throw new Exception('No valie info sent');
        }

        //set the custom fields to update
        $this->model->setCustomFields($request);

        //try to save all the fields we allow
        if ($this->model->save($request, $this->createFields)) {
            return $this->getById($this->model->id);
        } else {
            //if not thorw exception
            throw new Exception($this->model->getMessages()[0]);
        }
    }
public function create(): Response
    {
        $request = $this->request->getPost();

        if (empty($request)) {
            $request = $this->request->getJsonRawBody(true);
        }

        //we need even if empty the custome fields
        if (empty($request)) {
            throw new Exception('No valie info sent');
        }

        //set the custom fields to update
        $this->model->setCustomFields($request);

        //try to save all the fields we allow
        if ($this->model->save($request, $this->createFields)) {
            return $this->getById($this->model->id);
        } else {
            //if not thorw exception
            throw new Exception($this->model->getMessages()[0]);
        }
    }
public function create ( ) : Response { $ request = $ this -> request -> getPost ( ) ; if ( empty ( $ request ) ) { $ request = $ this -> request -> getJsonRawBody ( true ) ; } //we need even if empty the custome fields if ( empty ( $ request ) ) { throw new Exception ( 'No valie info sent' ) ; } //set the custom fields to update $ this -> model -> setCustomFields ( $ request ) ; //try to save all the fields we allow if ( $ this -> model -> save ( $ request , $ this -> createFields ) ) { return $ this -> getById ( $ this -> model -> id ) ; } else { //if not thorw exception throw new Exception ( $ this -> model -> getMessages ( ) [ 0 ] ) ; } }
Add a new item.

@method POST
url /v1/controller

@return \Phalcon\Http\Response
@throws \Exception
Add a new item .