我从 5.1 开始使用 laravel,我一直在使用 Model::create
方法来创建新的数据库记录。目前,我需要深入研究 laravel API 以找出该方法的返回类型(因为我忘记了这一点,而且自从我上次使用 Laravel 框架以来事情可能会发生变化)。
所以,当我试图找到 static create(..)
方法时,我发现自 5.3
版本以来,该方法的 api 文档丢失了。
该方法缺少 api 文档的原因是什么?使用静态 create
方法是否仍然安全,或者它会被弃用?
此外,laravel 文档缺少有关嵌套 Controller 的信息,该信息位于 laravel 5.2
和 5.3
文档中...
最佳答案
The create & forceCreate Methods
The
Model::create
&Model::forceCreate
methods have been moved to theIlluminate\Database\Eloquent\Builder
class in order to provide better support for creating models on multiple connections. However, if you are extending these methods in your own models, you will need to modify your implementation to call thecreate
method on the builder. For example:public static function create(array $attributes = []) { $model = static::query()->create($attributes); // ... return $model; }
关于php - Laravel 静态创建方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46158446/