8000 Merge pull request #751 from jasonlewis/patch-9 · laravel/laravel@cfc0577 · GitHub
[go: up one dir, main page]

Skip to content

Commit cfc0577

Browse files
committed
Merge pull request #751 from jasonlewis/patch-9
Allow find to be called non-statically on Eloquent models
2 parents 4b49ae4 + 6d5239b commit cfc0577

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

laravel/database/eloquent/model.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,9 @@ public static function update($id, $attributes)
230230
* @param array $columns
231231
* @return Model
232232
*/
233-
public static function find($id, $columns = array('*'))
233+
public function _find($id, $columns = array('*'))
234234
{
235-
$model = new static;
236-
237-
return $model->query()->where(static::$key, '=', $id)->first($columns);
235+
return $this->query()->where(static::$key, '=', $id)->first($columns);
238236
}
239237

240238
/**
@@ -746,10 +744,12 @@ public function __call($method, $parameters)
746744
return static::$$method;
747745
}
748746

747+
$underscored = array('with', 'find');
748+
749749
// Some methods need to be accessed both staticly and non-staticly so we'll
750750
// keep underscored methods of those methods and intercept calls to them
751751
// here so they can be called either way on the model instance.
752-
if (in_array($method, array('with')))
752+
if (in_array($method, $underscored))
753753
{
754754
return call_user_func_array(array($this, '_'.$method), $parameters);
755755
}

0 commit comments

Comments
 (0)
0