Skip to content

Commit

Permalink
Add fresh method to model.
Browse files Browse the repository at this point in the history
This method gets a fresh copy of the model using the ID from the
existing instance.
  • Loading branch information
taylorotwell committed Sep 8, 2014
1 parent 1ff457f commit 34f63cb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Expand Up @@ -675,6 +675,19 @@ public static function findOrFail($id, $columns = array('*'))
throw (new ModelNotFoundException)->setModel(get_called_class());
}

/**
* Reload a fresh model instance from the database.
*
* @param array $with
* @return $this
*/
public function fresh(array $with = array())
{
$key = $this->getKeyName();

return $this->exists ? static::with($with)->where($key, $this->getKey())->first() : null;
}

/**
* Eager load relations on the model.
*
Expand Down

0 comments on commit 34f63cb

Please sign in to comment.