protected function createModel(Resource $resource)
    {
        $model = new $resource->model_class;
        $model->fill($resource->data);

        $result = $model->save();
        if ($result === true) {
            return $model;
        }

        $code = (empty($resource->data) || $result === null)
            ? static::ERROR_INVALID_PAYLOAD
            : static::ERROR_INTERNAL_SERVER;

        $message = "Resource '$resource->name' could not be created: ";

        if (is_string($result)) {
            $message .= "Database failure ($result)";
        } elseif ($result === false) {
            $message .= 'post-save failure';
        } else {
            $message .= 'pre-save failure';
        }

        $this->sendError($code, $message);
    }
protected function createModel(Resource $resource)
    {
        $model = new $resource->model_class;
        $model->fill($resource->data);

        $result = $model->save();
        if ($result === true) {
            return $model;
        }

        $code = (empty($resource->data) || $result === null)
            ? static::ERROR_INVALID_PAYLOAD
            : static::ERROR_INTERNAL_SERVER;

        $message = "Resource '$resource->name' could not be created: ";

        if (is_string($result)) {
            $message .= "Database failure ($result)";
        } elseif ($result === false) {
            $message .= 'post-save failure';
        } else {
            $message .= 'pre-save failure';
        }

        $this->sendError($code, $message);
    }
protected function createModel ( Resource $ resource ) { $ model = new $ resource -> model_class ; $ model -> fill ( $ resource -> data ) ; $ result = $ model -> save ( ) ; if ( $ result === true ) { return $ model ; } $ code = ( empty ( $ resource -> data ) || $ result === null ) ? static :: ERROR_INVALID_PAYLOAD : static :: ERROR_INTERNAL_SERVER ; $ message = "Resource '$resource->name' could not be created: " ; if ( is_string ( $ result ) ) { $ message .= "Database failure ($result)" ; } elseif ( $ result === false ) { $ message .= 'post-save failure' ; } else { $ message .= 'pre-save failure' ; } $ this -> sendError ( $ code , $ message ) ; }
Creates a Model in the Database

@param Resource $resource Processed route

@return Model

@throws RouterException If could not save the new Model
Creates a Model in the Database