shouldUpdate example

return $this;
    }

    /** * This method is called on save to determine if entry have to be updated * If this method return false insert operation will be executed * * @param array|object $data Data */
    protected function shouldUpdate($data): bool
    {
        if (parent::shouldUpdate($data) === false) {
            return false;
        }

        if ($this->useAutoIncrement === true) {
            return true;
        }

        // When useAutoIncrement feature is disabled, check         // in the database if given record already exists         return $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1;
    }

    

    public function save($data): bool
    {
        if (empty($data)) {
            return true;
        }

        if ($this->shouldUpdate($data)) {
            $response = $this->update($this->getIdValue($data)$data);
        } else {
            $response = $this->insert($data, false);

            if ($response !== false) {
                $response = true;
            }
        }

        return $response;
    }

    
Home | Imprint | This part of the site doesn't use cookies.