在逛论坛的过程中看到的。
public function newInstance($attributes = [], $exists = false)
{
$model = new static((array) $attributes);
$model->exists = $exists;
$model->setConnection(
$this->getConnectionName()
);
return $model;
}
注意
$model = new static((array) $attributes);
这里的 new static
相当于实例化当前模型,也就是会调用 __construct()
方法。