Laravel 的 increment () 和 decrement () 方法疑问?
laravel 的中有两种数据库操作方法,一种是通过DB对象,一种是通过model对象
在DB对象中 increment() 和 decrement() 方法的访问控制是public。
而在model 对象中方法控制是 protected。
Model 类通过以下方式调用两个方法
public function __call($method, $parameters)
{
if (in_array($method, ['increment', 'decrement'])) {
return $this->$method(...$parameters);
}
return $this->newQuery()->$method(...$parameters);
}
通过 call 方法调用将继承方法转换成可外部调用的方法。这么写的深意在哪里呢?
高认可度评论:
要学会去追代码的历史记录
https://github.com/laravel/framework/commi...
https://github.com/laravel/framework/commi...
要学会去追代码的历史记录