LMongo\Eloquent\Model::save PHP Method

save() public method

Save the model to the database.
public save ( ) : boolean
return boolean
    public function save()
    {
        $query = $this->newQueryWithDeleted();
        // If the "saving" event returns false we'll bail out of the save and return
        // false, indicating that the save failed. This gives an opportunities to
        // listeners to cancel save operations if validations fail or whatever.
        if ($this->fireModelEvent('saving') === false) {
            return false;
        }
        // If the model already exists in the database we can just update our record
        // that is already in this database using the current IDs in this "where"
        // clause to only update this model. Otherwise, we'll just insert them.
        if ($this->exists) {
            $saved = $this->performUpdate($query);
        } else {
            $saved = $this->performInsert($query);
        }
        if ($saved) {
            $this->finishSave();
        }
        return $saved;
    }

Usage Example

 /**
  * Saves the model instance to database. If necessary, it will purge the model attributes
  * of unnecessary fields. It will also replace plain-text password fields with their hashes.
  *
  * @param array $options
  * @return bool
  */
 protected function performSave(array $options)
 {
     if ($this->autoPurgeRedundantAttributes) {
         $this->attributes = $this->purgeArray($this->attributes);
     }
     if ($this->autoHashPasswordAttributes) {
         $this->attributes = $this->hashPasswordAttributes($this->attributes, static::$passwordAttributes);
     }
     return parent::save($options);
 }
All Usage Examples Of LMongo\Eloquent\Model::save
Model