gpt4 book ai didi

php - Laravel 静态创建方法

转载 作者:可可西里 更新时间:2023-11-01 01:13:36 25 4
gpt4 key购买 nike

我从 5.1 开始使用 laravel,我一直在使用 Model::create 方法来创建新的数据库记录。目前,我需要深入研究 laravel API 以找出该方法的返回类型(因为我忘记了这一点,而且自从我上次使用 Laravel 框架以来事情可能会发生变化)。

所以,当我试图找到 static create(..) 方法时,我发现自 5.3 版本以来,该方法的 api 文档丢失了。

该方法缺少 api 文档的原因是什么?使用静态 create 方法是否仍然安全,或者它会被弃用?

此外,laravel 文档缺少有关嵌套 Controller 的信息,该信息位于 laravel 5.25.3 文档中...

最佳答案

来自upgrade docs for 5.4

The create & forceCreate Methods

The Model::create & Model::forceCreate methods have been moved to the Illuminate\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 the create 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com