Commit cfc0577d authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #751 from jasonlewis/patch-9

Allow find to be called non-statically on Eloquent models
parents 4b49ae42 6d5239bf
...@@ -230,11 +230,9 @@ abstract class Model { ...@@ -230,11 +230,9 @@ abstract class Model {
* @param array $columns * @param array $columns
* @return Model * @return Model
*/ */
public static function find($id, $columns = array('*')) public function _find($id, $columns = array('*'))
{ {
$model = new static; return $this->query()->where(static::$key, '=', $id)->first($columns);
return $model->query()->where(static::$key, '=', $id)->first($columns);
} }
/** /**
...@@ -746,10 +744,12 @@ abstract class Model { ...@@ -746,10 +744,12 @@ abstract class Model {
return static::$$method; return static::$$method;
} }
$underscored = array('with', 'find');
// Some methods need to be accessed both staticly and non-staticly so we'll // Some methods need to be accessed both staticly and non-staticly so we'll
// keep underscored methods of those methods and intercept calls to them // keep underscored methods of those methods and intercept calls to them
// here so they can be called either way on the model instance. // here so they can be called either way on the model instance.
if (in_array($method, array('with'))) if (in_array($method, $underscored))
{ {
return call_user_func_array(array($this, '_'.$method), $parameters); return call_user_func_array(array($this, '_'.$method), $parameters);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment