Laravel Faker - create 和 make 之间有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44119401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Faker - What's the difference between create and make
提问by Simon Suh
I have the following code:
我有以下代码:
$this->actingAs(factory('App\User')->create());
$thread = factory('App\Thread')->make();
what is the difference between create() and make() and why is it not listed in the helper functions page in the Laravel documentation? Thank you! :)
create() 和 make() 之间有什么区别,为什么它没有列在 Laravel 文档的辅助函数页面中?谢谢!:)
回答by Alex Harris
create
persists to the database while make
just creates a new instance of the model.
create
持久化到数据库,同时make
只创建模型的新实例。
The
create
method not only creates the model instances but also saves them to the database using Eloquent's save method
该
create
方法不仅创建模型实例,还使用 Eloquent 的 save 方法将它们保存到数据库中
https://laravel.com/docs/5.4/database-testing#using-factories
https://laravel.com/docs/5.4/database-testing#using-factories
If you'd like to see the source code differences between make and create you can see them in src/Illuminate/Database/Eloquent/FactoryBuilder.php
如果您想查看 make 和 create 之间的源代码差异,可以在 src/Illuminate/Database/Eloquent/FactoryBuilder.php
回答by Chirag Prajapati
Laravel create method is created the model instance and save data in the database.
Make function has created the instance of the class.