src/Model.php
public function save()
    {

        $fields = array_except($this->attributes, ["_index", "_type", "_id", "_score"]);

        if ($this->exists()) {

            // Update the current document

            $this->newQuery()->id($this->getID())->update($fields);

        } else {

            // Check if model key exists in items

            if (array_key_exists("_id", $this->attributes)) {
                $created = $this->newQuery()->id($this->attributes["_id"])->insert($fields);
                $this->_id = $this->attributes["_id"];
            } else {
                $created = $this->newQuery()->insert($fields);
                $this->_id = $created->_id;
            }

            $this->setConnection($this->getConnection());
            $this->setIndex($created->_index);

            // Match earlier versions

            $this->_index = $created->_index;
            $this->_type = $this->type;

            $this->exists = true;
        }

        return $this;
    }
public function save()
    {

        $fields = array_except($this->attributes, ["_index", "_type", "_id", "_score"]);

        if ($this->exists()) {

            // Update the current document

            $this->newQuery()->id($this->getID())->update($fields);

        } else {

            // Check if model key exists in items

            if (array_key_exists("_id", $this->attributes)) {
                $created = $this->newQuery()->id($this->attributes["_id"])->insert($fields);
                $this->_id = $this->attributes["_id"];
            } else {
                $created = $this->newQuery()->insert($fields);
                $this->_id = $created->_id;
            }

            $this->setConnection($this->getConnection());
            $this->setIndex($created->_index);

            // Match earlier versions

            $this->_index = $created->_index;
            $this->_type = $this->type;

            $this->exists = true;
        }

        return $this;
    }
public function save ( ) { $ fields = array_except ( $ this -> attributes , [ "_index" , "_type" , "_id" , "_score" ] ) ; if ( $ this -> exists ( ) ) { // Update the current document $ this -> newQuery ( ) -> id ( $ this -> getID ( ) ) -> update ( $ fields ) ; } else { // Check if model key exists in items if ( array_key_exists ( "_id" , $ this -> attributes ) ) { $ created = $ this -> newQuery ( ) -> id ( $ this -> attributes [ "_id" ] ) -> insert ( $ fields ) ; $ this -> _id = $ this -> attributes [ "_id" ] ; } else { $ created = $ this -> newQuery ( ) -> insert ( $ fields ) ; $ this -> _id = $ created -> _id ; } $ this -> setConnection ( $ this -> getConnection ( ) ) ; $ this -> setIndex ( $ created -> _index ) ; // Match earlier versions $ this -> _index = $ created -> _index ; $ this -> _type = $ this -> type ; $ this -> exists = true ; } return $ this ; }
Save data to model
@return string
Save data to model