简体   繁体   English

Laravel Framework是否在启动时实例化每个模型类?

[英]Does Laravel Framework instantiate every model class at boot?

With , where , hasMany etc. methods of Eloquent class are not static. WithwherehasMany雄辩类等方法不是一成不变的。

However we call these functions like that: 但是,我们将这些函数称为:

// Post is a child of Model class.
Post::where(...); // we don't use New keyword.

So, does Laravel Framework initiate all Model instances before we call their methods? 那么,在我们调用他们的方法之前,Laravel Framework是否会启动所有Model实例?

In the Eloquent's Model class, you have the below function which handles the static method calls dynamically. 在Eloquent的Model类中,您具有以下函数,该函数动态处理静态方法调用。

public static function __callStatic($method, $parameters)
{
    return (new static)->$method(...$parameters);
}

As you can see, it creates an instance of the Model class on which a non static method is invoked statically, then invokes that method on the instance. 如您所见,它创建了一个Model类的实例,静态调用非静态方法,然后在实例上调用该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM