Return a boolean success or failure when saving Eloquent models.

This commit is contained in:
Taylor Otwell 2011-08-08 11:04:50 -05:00
parent 87a65c2032
commit 4243e721ca
1 changed files with 5 additions and 5 deletions

View File

@ -353,7 +353,7 @@ private function intermediate_table($model)
/** /**
* Save the model to the database. * Save the model to the database.
* *
* @return void * @return bool
*/ */
public function save() public function save()
{ {
@ -376,16 +376,16 @@ public function save()
// Otherwise, we will insert the model and set the ID attribute. // Otherwise, we will insert the model and set the ID attribute.
if ($this->exists) if ($this->exists)
{ {
$this->query->where_id($this->attributes['id'])->update($this->dirty); $success = ($this->query->where_id($this->attributes['id'])->update($this->dirty) === 1);
} }
else else
{ {
$this->attributes['id'] = $this->query->insert_get_id($this->attributes); $success = is_numeric($this->attributes['id'] = $this->query->insert_get_id($this->attributes));
} }
$this->exists = true; ($this->exists = true) and $this->dirty = array();
$this->dirty = array(); return $success;
} }
/** /**