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;
}
/** * 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); }