The challenge wherein the Eloquent model involves a bit of magic that happens behind the scenes. First, take an example:
User::where(’name’, ‘Joe’)->first;
There is no static method wherethat exists in a class Modelthat extends a class User.
What happens is that the PHP magic method is called __callStatic, which then tries to call the method where.
public static function __callStatic($method, $parameters)
{
$instance = new static;
return call_user_func_array([$instance, $method], $parameters);
}
where, PHP- __call, Model.
public function __call($method, $parameters)
{
if (in_array($method, ['increment', 'decrement'])) {
return call_user_func_array([$this, $method], $parameters);
}
$query = $this->newQuery();
return call_user_func_array([$query, $method], $parameters);
}
, , :
$query = $this->newQuery();
Eloquent , where.
, `` `User:: where()` ` :
Illuminate\Database\Eloquent\Builder::where()
Builder, , , where(), get(), first(), update() ..
Laracasts () , Eloquent , .